Thread: OpenGL Wierd **** - Order of Drawing Stuff?

  1. #1
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465

    OpenGL Wierd **** - Order of Drawing Stuff?

    I am trying to figure out some wierd ****.

    I have an object I defined as a cube which is for quadrilaterals as the faces,I couldn't figure out a cleverway to make it use a quad_strip with the vertices. Whatever. So, then I have a draw routine for it.

    Code:
    void cube::draw(void)
    {
    	glLoadIdentity();
    
    	glTranslatef(0.0f, 0.0f, -0.2f);
    	glRotatef(rotate / 2, 0, 1, 0);
    	glRotatef(rotate, 1, 0, 0);
    	
    	glBegin(GL_QUADS);
    
    	for(int i = 0; i < 6; ++i)
    	{
    		glColor3f(colors[i].x, colors[i].y, colors[i].z);
    		
    		for(int k = 0; k < 4; ++k)
    		{
    			glVertex3f(faces[i][k].x, faces[i][k].y, faces[i][k].z);
    		}
    	}
    
    	glEnd();
    }
    And it does some wierd stuff. Dude! Like, so the thing is all rotating around n stuff. And then it seems like when some face is facing us, it may be drawn earlier than the one that is the back face, and then the backfaceappears to be the front. It's kind of hard to describe, it looks like that wierd figure-ground illusion with the wire cube with things jumping to the front and all. Here's a screenshot of it. http://img.photobucket.com/albums/v2...untitled-1.jpg I want to figure out how to make it just look like a solid cube instead of sometimes being able to 'see through it' or the illusion of that because things are drawn in front. Or, that'smy wierd hypothesis. Any ideas?

  2. #2
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    Are you using backface culling?
    Are you using depth testing?
    What is your near-clip set to?
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  3. #3
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    I am not using backface culling. I don't know what depth testing is, and do not think I am using it. I believe my near clip is 0.1, and the far clip is 100.0f

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    >What is your near-clip set to?

    x2


    Move the box back a little and render it, it looks like your near clip is cutting it off.

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Your near clipping plane is clipping that box. And from the photo you are obviously not using backface culling or you wouldn't see the other side of the cube after the clip since this would not change the clockwise or counter-clockwise orientation of the vertices for the backfaces.

  6. #6
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Can you explain this sentence more?

    >> And from the photo you are obviously not using backface culling or you wouldn't see the other side of the cube after the clip since this would not change the clockwise or counter-clockwise orientation of the vertices for the backfaces.

    Does the orientation of the vertices matter or something? How consistent do they need to be?

  7. #7
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    I have something like this:

    Code:
    cube::cube(point a, point b)
    	: rotate(0)
    {
    	// Backface
    	faces[5][0] = point(b.x, a.y, b.z);
    	faces[5][1] = point(a.x, a.y, b.z);
    	faces[5][2] = point(a.x, b.y, b.z);
    	faces[5][3] = point(b.x, b.y, b.z);
    
    	// Rightsideface
    	faces[4][0] = point(b.x, a.y, b.z);
    	faces[4][1] = point(b.x, a.y, a.z);
    	faces[4][2] = point(b.x, b.y, a.z);
    	faces[4][3] = point(b.x, b.y, b.z);
    
    	//Leftsideface
    	faces[3][0] = point(a.x, a.y, a.z);
    	faces[3][1] = point(a.x, a.y, b.z);
    	faces[3][2] = point(a.x, b.y, b.z);
    	faces[3][3] = point(a.x, b.y, a.z);
    
    	// Frontface
    	faces[2][0] = point(b.x, a.y, a.z);
    	faces[2][1] = point(a.x, a.y, a.z);
    	faces[2][2] = point(a.x, b.y, a.z);
    	faces[2][3] = point(b.x, b.y, a.z);
    
    	// Topface
    	faces[1][0] = point(b.x, a.y, b.z);
    	faces[1][1] = point(a.x, a.y, b.z);
    	faces[1][2] = point(a.x, a.y, a.z);
    	faces[1][3] = point(b.x, a.y, a.z);
    
    	// Bottomface
    	faces[0][0] = point(b.x, b.y, b.z);
    	faces[0][1] = point(a.x, b.y, b.z);
    	faces[0][2] = point(a.x, b.y, a.z);
    	faces[0][3] = point(b.x, b.y, a.z);
    
    	// Colors dude
    	colors[0] = point(1.0f, 0.0f, 0.0f);
    	colors[1] = point(0.0f, 1.0f, 0.0f);
    	colors[2] = point(0.0f, 0.0f, 1.0f);
    	colors[3] = point(0.5f, 0.0f, 0.0f);
    	colors[4] = point(0.0f, 0.6f, 0.0f);
    	colors[5] = point(0.0f, 0.0f, 0.5f);
    
    	// cnormals();
    }
    I changed it so all the vertices are clockwise, and I do not use normals in my code. I have a routine which tries calculating and hardcoding them but it doesn't seem to have any effect if it's there or not. I am not using backface culling, and I did resolve the clipping plane dealio, but I can still get pictures that look like the attachment.

  8. #8
    Darkness Prevails Dark_Phoenix's Avatar
    Join Date
    Oct 2006
    Location
    Houston, Texas
    Posts
    174
    Quote Originally Posted by Tonto
    Does the orientation of the vertices matter or something?
    I am by no means an expert but I have read that the order of vertices does need to be clockwise.
    Using Code::Blocks and Windows XP

    In every hero, there COULD be a villain!

  9. #9
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    >> I am by no means an expert but I have read that the order of vertices does need to be clockwise.

    I found in this link in the section called 'winding' that the orientation does matter, and that counter-clockwise faces are seen as a front. http://www.quepublishing.com/article...&seqNum=7&rl=1 Well, all my faces are oriented in a counter-clockwise manner, does that mean they are all percieved as a front?

  10. #10
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465


    Code:
    glEnable(GL_DEPTH_TEST);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  2. OpenGL Question...simple (triangle drawing stuff)
    By incognito in forum Game Programming
    Replies: 7
    Last Post: 03-15-2003, 08:47 PM
  3. Problems Drawing OpenGL to the Client Area
    By Niytaan in forum Windows Programming
    Replies: 3
    Last Post: 10-27-2002, 07:15 PM
  4. So.. what's the difference between DirectX and OpenGL?
    By QuestionC in forum Game Programming
    Replies: 6
    Last Post: 01-19-2002, 06:18 PM
  5. OpenGL question
    By Malek in forum Windows Programming
    Replies: 1
    Last Post: 09-10-2001, 12:00 PM