# OpenGL Vertex Arrays & Orthogonal

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

## Recommended Posts

I already have an existing system where vertex arrays are stored in render operations. But these vertex arrays are assumed to be of a certain size according to its use and one of such assumptions is that the x, y and z coordinates are in the array. However I now want to draw in orthogonal projection and as such, drawing in the usual way seems not to yield any result at all. I get a blank screen without any drawing. I don't want to change the vertex array classes to fit these 2D constructs, but is there a way where I can make OpenGL accept 3D vertex arrays and automatically discard the z component?

##### Share on other sites
Hmm, I don't think I explained my situation clearly enough. I want to do 2D graphics in OpenGL but don't want to change my existing system just for 2D graphics.

I'm using vertex arrays to store vertices, texture coordinates, normals and other VAs that I can send to the renderer in a single RenderOperation.

Could I follow this existing method but instead display to an orthographic projection?

Also, I've never worked with vertex shaders before.

##### Share on other sites
When using an orthographic projection in OpenGL all that is changed is the projection matrix. This means that you can use all the OpenGL features just as would with an perspective projection. Thus any drawing code you've got should work just fine in an orthographic projection. As you're getting a black screen you must be doing something wrong somewhere. Can you give specifics on what you're actually trying to do or post some code?

##### Share on other sites
Did you use gluOrtho2d? If yes, then the near and far clipping plane is implicitely set to 0 and 1, respectively. This might be the reason why you get a blank screen: The z-coordinates of the vertex arrays are outside this range and everything gets clipped.

Try using glOrtho() and set the near and far plane accordingly to the z-coordinates, i.e. near < all z-coordinates < far.

##### Share on other sites
I've got something to display on screen and I think i've figured it out. Turns out that the origin is now at the bottom left of the screen. How did that happen? And I was drawing my objects downwards out of the screen. My bad.

##### Share on other sites
In OpenGL, the bottom left is the starting point. You have to do some corrections for it (basically subtract the viewport's vertical height). Anyone who has used ortho2d and gluUnProject is forced to do this.

I still can't figure out why ;)

##### Share on other sites
Thanks for the confirmation. So it would still be easier if we used cartesian coordinates with the origin at the top left? How did you guys do your GUIs?

##### Share on other sites
>>I still can't figure out why ;)<<

perhaps its cause maths does it that way ie u draw your graphs like so

^
|Y
|
-->X

also when u go into the 3d dimension x,y,(Z) it would be bad/inconsistant if u changed from y going down (in 2d) to y going up (in 3d)

##### Share on other sites
maybe try this:
glViewport(0,MODE_HEIGHT-height,width,height);//set new projectionglMatrixMode(GL_PROJECTION);glLoadIdentity();glOrtho(0,static_cast<GLdouble>(width),static_cast<GLdouble>(height),0,-1.0,1.0);//back to modelviewglMatrixMode(GL_MODELVIEW);glLoadIdentity();

MODE_HEIGHT is the height of the current video mode (eg. 600 or 768)

1. 1
2. 2
3. 3
4. 4
5. 5
Rutin
17

• 9
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631420
• Total Posts
2999990
×