Advertisement Jump to content
Sign in to follow this  

Weird things happen

This topic is 4239 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I´ve been working with this code, now im trying to make the Triangle go further, so it looks smaller, ok, i put translate in the Z something negative, but something totally different happens, it goes back but the rotation changes and it becomes a square for a second!!But everything goes great if a dont change the settings os translate. What can i do to change the zoom of the camera?? i also tried to translate the PROJECTION matrix but it doesnt work, the windows is all black, any idea why? Thank u #include <windows.h> #include <GL/glut.h> #include <stdio.h> // Para cada objeto que vamos a representar necesitamos una Matrix, que va a //va a reprensetar los puntos x,y,z que ocupa el objeto en el espacio float ang = 0.0f; int max = 64; BOOLEAN flag=FALSE; int posx,posy; void mouse(int btn, int state, int x, int y){ if((btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN)){ //glTranslatef(0.0f,1.0f,0.0f); flag=TRUE; posx=x; posy=y; } } void draw(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); //Carga la matriz identidad gluLookAt(0.0f, 0.0f, 4.0f, //eye 0.0f, 0.0f, 0.0f, //center 0.0f, 1.0f, 0.0f);//up*/ //glLoadIdentity(); //Carga la matriz identidad glColor3f(1.0f,0.0f,0.0f); glPushMatrix(); glTranslatef(-1.5f,0.0f,-1.0f); glRotatef(ang,1.0f,0.0f,0.0f); // Rotate The Triangle On The Y axis ( NEW ) // Move Left 1.5 Units And Into The Screen 6.0 glBegin(GL_TRIANGLES); glColor3f(0.0f,0.0f,0.0f); glVertex3f( 0.0f, 1.0f, 0.0f); // Top glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right glEnd(); glPopMatrix(); glTranslatef(1.5f,0.0f,0.0f); glRotatef(ang,0.0f,1.0f,0.0f); //glPopMatrix(); // Move Right 3 Units glBegin(GL_QUADS); glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left glEnd(); //glPopMatrix(); if(!flag==TRUE){ /*glBegin(GL_TRIANGLES); glVertex3f( 0.0f, 1.0f, 0.0f); // Top glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right glEnd();*/ ang+=0.2f; } glFlush(); // Asegura que los comandos anteriores se vana ejecutar } void display(void) { int i; GLenum err; glClear(GL_ACCUM_BUFFER_BIT); //Vacia ese buffer, porque es posible que tenga residuos for (i=0; i<max; i++) { draw(); glAccum(GL_ACCUM, 1.f/max); } glAccum(GL_RETURN, 1.f); glutSwapBuffers(); } void reshape(int w, int h) { glMatrixMode(GL_PROJECTION); //Con esta función se elige en que matriz vamos a realizar los cambios glLoadIdentity(); gluPerspective(55.0f, (float)w/(float)h, 0.3f, 5.0f); glViewport(0,0,w,h); glMatrixMode(GL_MODELVIEW); } void idle(void) { glutPostRedisplay(); } void init(void) { glReadBuffer( GL_BACK); glDrawBuffer( GL_BACK); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClearAccum(0.0f, 0.0f, 0.0f, 1.0f); glClearDepth(1.0f); } int main(int argc, char *argv[]) { // inizializzo la libreria glutInit(&argc, argv); // definisco le proprieta della finestra e del display glutInitWindowPosition(16, 16); glutInitWindowSize(512, 512); glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE | GLUT_ACCUM); // creo la fienstra glutCreateWindow("OpenGL Test"); // registro le callback glutDisplayFunc(display); glutReshapeFunc(reshape); glutIdleFunc(idle); init(); glutMouseFunc (mouse); //estoy probando con el ratón // loop infinito glutMainLoop(); return 0; }

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!