View Full Version : coordinates? (beginner question)
hi, i want to learn opengl but there is one thing i dont understand which also isnt explained in the tutorials:
how do i get the coordinates of the rim of my monitor ? i mean, how do i know for example when i want to draw a background how big the polygon has to be to cover the whole monitor but also to show the whole texture ? also this float stuff is crazy, why cant it be like the resolution is 640x480 and i just enter the pixels as coordinates ?
sorry i just dont understand it, could someone be friendly and explain it to me :p
06-03-2004, 07:47 AM
The float stuff is quite handy once you get to understand it. It helps with interpolation and percentages.
The viewing area defined is usually based off of the client area of the window you are rending into. (GetClientRect, or the width and height you pass in as parameters when creating the window).
You can use regular screen coordinates if you set up an orthographic projection (using glOrtho()). This isn't the best way to render 3D graphics though...
Perspective projections is where it gets interesting.
search for Nehe on google and check out those tutorials. Setting up your viewing area and world space might seem strange at first, but once you learn to work in the space you've set up it's really not that bad.
06-03-2004, 08:00 AM
The magic word is 'transformation'.
These operations allow to convert to and from several different space coordinates. There are stored as matrices (ie. modelview and projection) and you combine them with matrix multiplications.
To get a fullscreen quad, you have several choice. here is one simple way to do it :
// let's reset the 2 main transformation matrices
glMatrixMode( GL_PROJECTION );
// glScaled(1.0/640,1.0/480,1.0); // uncomment to go for pixel coordinates
glMatrixMode( GL_MODELVIEW );
// let's draw that fullscreen textured quad
// (don't forget to initialise and bind a texture before)
// texCoord specify what part of the texture goes to this vertex.
// vertex2 specify a 2d coordinate
glTexCoord2f( 0.0f,0.0f );
glVertex2f( -1.0f,-1.0f );
glTexCoord2f( 0.0f, 1.0f );
glVertex2f( -1.0f, 1.0f );
glTexCoord2f( 1.0f, 1.0f );
glVertex2f( 1.0f, 1.0f );
glTexCoord2f( 1.0f,0.0f );
glVertex2f( 1.0f,-1.0f );
glEnd();The code is not tested but should work. The texcoords are values in the range [0,1] for each coordinate of the texture, whatever its size. Of course the vertex coordinates will need to be adapted if you go for pixel screen coords.
You will find plenty tutorials by searching google about matrix, transformation, projection, coordinates, etc.
Hope it helps.
06-03-2004, 06:38 PM
OpenGL uses floats because your 3D world is created using vectors and because the math required to create a 3D world.
When not use pixels you ask, imagine switching resolution from a say 640 x 480 screen to a 800 x 600. An image 640 x 480 would no longer fill the screen.
OpenGL does a lot of this work for you, by having a world coordinte system(projection) and a screen coordinate system (view port).
Lets say you define your world in a 10 unit x 10 unit box ortho projection, we need only define our window size and OpenGL will fill the screen with our world no matter the size.
So you would set your background polygon to 0,0 - 10,10 to fill the screen and then just reset the view port to what ever resolution you are running.
One other thing about vector data, unlike working in pixels. The higher the resolution the sharper looking the vector lines become vs. what happens to pixels if you increase the resolution and streach a small pixel image accross a larger area.
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.