# OpenGL what's a projection

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

## Recommended Posts

Hi. Noob here. I'm having trouble understanding the proper use of projections. I'm trying to to do a couple of things: draw text, draw a couple of primitives and draw a set of spiraling points. A couple of tutorials that I've read change the viewing mode, usually in the callback function that changes the window size. I have *some* idea of what they are doing, but I'm still confused. One of Nehe's tutorials I read about text set projections like so:  if (h==0) // Prevent A Divide By Zero By { h=1; // Making Height Equal One } glViewport(0,0,w,h); // Reset The Current Viewport glMatrixMode(GL_PROJECTION); // Select The Projection Matrix glLoadIdentity(); // Reset The Projection Matrix glOrtho(0.0f,640,480,0.0f,0.0f,1.0f); // Create Ortho 640x480 View (0,0 At Top Left) glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix glLoadIdentity();  That works fine for text, but other primitives that were showing don't show anymore. I've read some definitions about orthographic and perspective views, in OpenGL bible, first edition. But the author didn't show some examples as he was explaining it, so I don't know how to manage them as the programs goes. What's the proper way of managing these things? I want to be able to draw things(geometry, text, etc) based on different modes of my choosing. For instance, some of them would be: 1) pixel coordinates (the width and height of the window, in pixels). This would be good for drawing text and images at very specific pixels on screen. 2) in logical coordinates that range from 0-100. This would be good for drawing text and images by specifying a range, from 0-100, of where to draw the item withing the screen. The screen would always be defined by that range, so no matter how big of small the screen is, things would still be placed with the same spacing. 3) A coordinate for drawing 3d elements that range from -100 to +100 in all 3 axis, with the origin a (0,0,0). I would like to be able to draw anything based on any of the above coordinates. But again, the problem is that I don't understand how to really do that. I would really appreciate any info or links to good info about this subject. thanks vl@d

##### Share on other sites
hmmm.....
A new openGL Fan.

ok! the openGL is by far the easiest and simplest way for me to put things on screen.
don't get stuck in projections, if u wanna put something on screen, NEHE's code is the best code written about a simple projection, no-one can do more than that.

But for ur problem first understand that openGL is a right handed coordinate system, and it means that the positive z is towards u from the monitor and poistive x is right and positive y is towards up. so keeping this in mind give ur vertex to openGL and you will see everything as expacted like to draw a sqaure at Z=-2:

glTranslatef(0.0f, 0.0f, -5.0f); //move into screen 5 units

//create bottom left vertex
glVertex3f(-1.0f, -1.0f, 0.0f);

//left top
glVertex3f(-1.0f, 1.0f, 0.0f);

//right top
glVertex3f(1.0f, 1.0f, 0.0f);

//right bottom
glVertex3f(1.0f, -1.0f, 0.0f);

glEnd();

this is way to do it, if you don't give vertices in properway then the whole polygon will get digenerated.

and lastly read the chapter 1-5 of NEHE carefully, it is good to start with solid foundation.

bye
RK - the one

##### Share on other sites
I recommend picking up a copy of the OpenGL Programming Guide (the Red Book). If you don't want to buy the latest version, although it is worth it, the old 1.1 version is free online here. For this particular question you should read chapter 3.

##### Share on other sites
This looks like what I'm looking for.

thanks.

1. 1
2. 2
frob
15
3. 3
Rutin
12
4. 4
5. 5

• 13
• 12
• 58
• 14
• 15
• ### Forum Statistics

• Total Topics
632123
• Total Posts
3004235

×