Thread: OpenGL Transformations

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    71

    OpenGL Transformations

    I've managed to load an image and texture map it. I am now trying to rotate this object. When I rotate it, it looks funny and I'm not sure why.

    Here are the relevant lines of code:

    Code:
    void initGL(void){
    	glEnable(GL_TEXTURE_2D);
    	glShadeModel(GL_SMOOTH);
    	glClearColor(0.0f,0.0f,0.0f,0.0f);
    	glClearDepth(1.0f);
    	glEnable(GL_DEPTH_TEST);
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    	glOrtho(0,640,480,0,-1,1);
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    }
    
    
    void drawBox(void){
    
    	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    	glBindTexture(GL_TEXTURE_2D,tname);
    
    	glPushMatrix();
    	glRotatef(rcubex,1.0f,0.0f,0.0f);
    //	glRotatef(rcubey,0.0f,1.0f,0.0f);
    //	glRotatef(rcubez,0.0f,0.0f,1.0f);
    	glBegin(GL_QUADS);
    
    		//front
    		glTexCoord2f(0,0);
    		glVertex3f(270,190,0);
    		glTexCoord2f(1,0);
    		glVertex3f(370,190,0);
    		glTexCoord2f(1,1);
    		glVertex3f(370,290,0);
    		glTexCoord2f(0,1);
    		glVertex3f(270,290,0);
    
    		//back
    		glTexCoord2f(0,0);
    		glVertex3f(270,190,100);
    		glTexCoord2f(1,0);
    		glVertex3f(370,190,100);
    		glTexCoord2f(1,1);
    		glVertex3f(370,290,100);
    		glTexCoord2f(0,1);
    		glVertex3f(270,290,100);
    
    		//right
    		glTexCoord2f(0,0);
    		glVertex3f(370,190,0);
    		glTexCoord2f(1,0);
    		glVertex3f(370,190,100);
    		glTexCoord2f(1,1);
    		glVertex3f(370,290,100);
    		glTexCoord2f(0,1);
    		glVertex3f(370,290,0);
    
    	glEnd();
    	glPopMatrix();
    	rcubex+= 0.3f;
    	rcubey+= 0.2f;
    	rcubez+= 0.4f;
    }
    I think it might have to do with what is in initGL()

  2. #2
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    Could you be more specific than "funny"? Blurry textures? Wrong colors? Wrong shape? Missing faces?
    Consider this post signed

  3. #3
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    I noticed you never set your prespective, a la glFrustrum or equivalent.

  4. #4
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    Ah, I see it now.

    There is a call to set the projection
    Code:
    glOrtho(0,640,480,0,-1,1);
    but znear and zfar are way too small to show the whole object; you'll only see the small slice that happens to be between -1 and 1.
    Consider this post signed

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    ...and that will only work if your entire object lies between -1 and 1. This will work fine for 2D where everything can be at z = 0.0f or z = 1.0f and objects are normally on the x/y plane but it will not work for anything else.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 04-11-2007, 03:43 AM
  2. Numerical System Transformations - Lecture
    By vurdlak in forum C++ Programming
    Replies: 2
    Last Post: 03-16-2006, 08:16 AM
  3. opengl model transformations
    By curlious in forum Game Programming
    Replies: 3
    Last Post: 09-06-2004, 02:30 PM
  4. DirectX transformations
    By confuted in forum Game Programming
    Replies: 9
    Last Post: 08-02-2003, 07:41 PM