Odd looking square

Started by
5 comments, last by Shadow1234567890 21 years, 8 months ago
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]
What do you mean ''Someday become a programmer?'' I'm a programmer right now!
Advertisement
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
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>.
Okay I guess I need to make a GL_QUAD...can a GL_QUAD be 3d? Well Ill find out soon cuz im goign to try it.
What do you mean ''Someday become a programmer?'' I'm a programmer right now!
Everything is 3D - it just depends on your projection matrix.

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
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
_______________________________________Pixelante Game Studios - Fowl Language
I made two squares (GL_QUADS) but they aren''t connected with lines, so it is just two 2d squares. Do I have to ''manually'' connect them with GL_LINES or is there a better way?
What do you mean ''Someday become a programmer?'' I'm a programmer right now!

This topic is closed to new replies.

Advertisement