Archived

This topic is now archived and is closed to further replies.

Shadow1234567890

Odd looking square

Recommended Posts

Here I have code that I thought would produce a square:
glBegin(GL_QUAD_STRIP);
	glVertex3f(0.0f, 0.0f, -1.0f);
	glVertex3f(1.0f, 0.0f, -1.0f);
	glVertex3f(1.0f, 1.0f, -1.0f);
	glVertex3f(0.0f, 1.0f, -1.0f);
glEnd();

SwapBuffers(g_HDC);
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
  
But for some reason the actual output looks all twisted. When I use the following code it works fine:
			glBegin(GL_QUAD_STRIP);
				glVertex3f(1.0f, 0.0f, -1.0f);
				glVertex3f(0.0f, 0.0f, -1.0f);
				glVertex3f(1.0f, 1.0f, -1.0f);
				glVertex3f(0.0f, 1.0f, -1.0f);
			glEnd();
			
			SwapBuffers(g_HDC);
			
			TranslateMessage(&msg);
			DispatchMessage(&msg);
	}
	return msg.wParam;
}
  
I thought it was rather odd that the latter produces what I expected, while the first one doesn't. I was wondering if someone could shed some light on why that was. The code was preceeded with all of the necessary window-creation code...the else clause of the while(!done) loop had the above code preceeded with:
			glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
			glLoadIdentity();
			glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);
			glColor3f(0.0f, 1.0f, 0.0f);
  
Thanks if you can help my feeble mind comprehend! [edited by - Shadow1234567890 on August 11, 2002 5:00:49 PM]

Share this post


Link to post
Share on other sites
The ordering of vertices quad strips is different to that of quads. It is necessary to make strips. Your best bet is to buy the OpenGL Programming Guide and check out the diagrams.


Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I''d guess it is because the vertices of the GL_QUAD_STRIP must be given in a specific order. See the GL_QUAD_STRIP picture <a href="http://fly.cc.fer.hr/~unreal/theredbook/chapter02.html">here</a>.

Share this post


Link to post
Share on other sites
First, let me suggest you switch to GL_TRIANGLE_STRIP, because its very fast although I haven''t used quad strips, from what you''ve posted they work the same way.

While a single quad is:
1-4
| |
2-3

A triangle strip (or in your case, quad strip) is:
1-3
|/|
2-4

Note that in the tri strip, you form a triangle first and then define the 4th point in order to make the second triangle. Adding a second quad would be like this:
1 3 5
2 4

1 3 5
2 4 6

It''s weird that a quad strip would take input that way, but since it does you might as well switch to triangle strips, faster and works the same.

------------
Where''d the engine go? Where''d it go? Aaaaaah!!
MSN: nmaster42@hotmail.com, AIM: LockePick42, ICQ: 74128155

Share this post


Link to post
Share on other sites