Ir ao conteúdo
  • Cadastre-se

Dúvida em OpenGL


dowlowd

Posts recomendados

Tenho que fazer um circulo se movimentar e depois criar alguma mudança que transforme o desenho. Então criei o circulo que se movimenta até o meio da tela, e pois cria quatro triangulos transformando na bandeira do Brasil. O problema é que o circulo e o triangulo se movimentam juntos, eu queria que o circulo se movimenta-se até o meio da tela e depois aparece-se os triangulos.

Obrigado pela ajuda.



#include <windows.h>
#include <gl/gl.h>
#include <GL/glut.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#define PI 3.1415926535


void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC)
{
wglMakeCurrent (NULL, NULL);
wglDeleteContext (hRC);
ReleaseDC (hWnd, hDC);
}

GLint x1 = 1;
GLint y = 1;
GLint xf = 1;
GLint yf = 1;
GLint zf = 1;
GLint tamanho = 550;
GLint larguraJanela = 100;
GLint alturaJanela = 280;
GLsizei rsize = 10;
GLint aux1 = 0;
GLint aux2 = 0;
GLint cont=0;/**/

void AntesDesenha(void) //450,280
{
if ((x1+tamanho) < (larguraJanela)) {
x1++;
}
else {
aux1=1;
}
if ((y+tamanho) < (alturaJanela)) {
y++;
}
else
{
aux2=1;
}
if( (aux1==1) && (aux2==1))
{
cont=1;
}

}

void DesenhaCirculo(void)
{

GLfloat angle=0;
int i=0;
GLfloat circle_points = 100;

glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_POLYGON);

// Desenha o circulo
for (i = 0; i < circle_points; i++)
{
angle = 2*PI*i/circle_points;
glColor3ub(0, 0, 255);
glVertex2f(130*cos(angle) + 135, 170*sin(angle) + 140-rsize);
}
glEnd();

// Executa os comandos OpenGL
glFlush();
}

void DesenhaTriangulo(void) {
glTranslatef(-250,-250,0);
glBegin(GL_TRIANGLES);
glColor3ub(0, 85, 0); glVertex2i( 0,0);
glColor3ub(0, 255, 0); glVertex2i(400,0);
glColor3ub(0, 255, 0); glVertex2i( 0,400);
glEnd();

glTranslatef(250,250,0);
glBegin(GL_TRIANGLES);
glColor3ub(0, 85, 0); glVertex2i(550,550);
glColor3ub(0, 255, 0); glVertex2i(550,150);
glColor3ub(0, 255, 0); glVertex2i(140,550);
glEnd();

glTranslatef(0,0,0);
glBegin(GL_TRIANGLES);
glColor3ub(0, 85, 0); glVertex2i(-250,550);
glColor3ub(0, 255, 0); glVertex2i(-250,150);
glColor3ub(0, 255, 0); glVertex2i( 150,550);
glEnd();

glTranslatef(250,-250,0);
glBegin(GL_TRIANGLES);
glColor3ub(0, 85, 0); glVertex2i( 300, -0);
glColor3ub(0, 255, 0); glVertex2i( 300,400);
glColor3ub(0, 255, 0); glVertex2i(-100, 0);
glEnd();
}


void Desenha(void) {
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glClear(GL_COLOR_BUFFER_BIT);
glLineWidth(3);

AntesDesenha();
glTranslatef(x1,y,0);
DesenhaCirculo();
//Sleep(30000);
// system("PAUSE");
//printf("teste %c", c);
if( cont==1 )
{
DesenhaTriangulo();
}

//DesenhaTriangulo();
glutSwapBuffers();
}


void Inicializa(void){
glClearColor(1.0f, 1.00f, 0.0f, 0.0f);
}

void AlteraTamanhoJanela(GLsizei w, GLsizei h){
if(h==0)
h=1;
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h) {
alturaJanela = 600*h/w;
larguraJanela = 800;
} else {
larguraJanela = 600*w/h;
alturaJanela = 800;
}
gluOrtho2D(0.0f, larguraJanela, 0.0f, alturaJanela);
}

int main(void){
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(800,600);
glutInitWindowPosition(1,1);
glutCreateWindow("Circulo");
glutDisplayFunc(Desenha);
glutIdleFunc(Desenha);
glutReshapeFunc(AlteraTamanhoJanela);
Inicializa();
glutMainLoop();
}


Link para o comentário
Compartilhar em outros sites

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

 

GRÁTIS: ebook Redes Wi-Fi – 2ª Edição

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!