GPWiki.org
GPWiki.org
It is currently Sun May 26, 2013 1:45 am

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Wed Sep 19, 2012 1:00 pm 
Rookie

Joined: Tue Sep 18, 2012 7:47 pm
Posts: 2
Hello, I'm trying to learn game programing. I already know PHP, Java and I'm learning C++. I've started to learn OpenGL & C++ interactions, trying to create a multiplatform program, with GLFW, and I have some issues regarding units.

The thing is that when I create a window (for example 800x600px) a unit in height is not the same as a unit in width. So if I create a rectangle with all of it's sides of 1 unit length, I get a rectangle with more pixels in width than in height.

I'm trying Nehe tutorials, but don't know how to solve that.


Top
 Profile  
 
PostPosted: Wed Sep 19, 2012 1:23 pm 
Shake'n'Baker

Joined: Thu Dec 29, 2011 2:33 pm
Posts: 62
Welcome Razican,

I am not into openGL yet, but as far as I know there are several ways to draw like:
glVertex2f, glVertex2v, glVertex2dv ...
Maybe the one you chose is a percentual calculation depending on the window size instead of a fixed one?

I started with openGL yesterday, using lazyfoos Tutorial, because I found Nehe to complicated*g*


Top
 Profile  
 
PostPosted: Wed Sep 19, 2012 2:18 pm 
Double Guru
User avatar

Joined: Fri Aug 12, 2005 8:58 am
Posts: 2009
Location: LA, CA
If you are drawing in model view space without a projection the center of the screen is 0,0 the left is -1 and right is 1, top is 1 and bottom is -1. This means that no matter what resolution you use it will just "stretch" the viewport to match your window size. If you are looking to do 2d work then you will want to make an orthographic projection, if you want to do 3d then you need to setup a perspective projection. Nehe uses an older version of opengl so the functions you will want to look at are glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far); and void gluPerspective(GLdouble fov, GLdouble aspect, GLdouble near, GLdouble far); (in modern opengl you would just create a projection matrix to pass to a shader).

Relevant links:
http://www.glprogramming.com/red/chapter03.html
http://www.cprogramming.com/tutorial/op ... tions.html

_________________
My Development Blog | My Website | My Current 3d Engine


Top
 Profile  
 
PostPosted: Wed Sep 19, 2012 6:36 pm 
Rookie

Joined: Tue Sep 18, 2012 7:47 pm
Posts: 2
Thanks for the links, they were really useful, but I didn't understand how to use glOrtho. What is a clipping plane? furthermore, I'm using gluPerspective. This is my window initialization:

Code:
   int width, height;

   glfwGetWindowSize(&width, &height);

   glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
   glClearDepth(1.0);
   glDepthFunc(GL_LESS);
   glEnable(GL_DEPTH_TEST);
   glShadeModel(GL_SMOOTH);

   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();

   if (height == 0) height = 1;

   gluPerspective(45.0f, width/height, 0.1f, 100.0f);

   glMatrixMode(GL_MODELVIEW);
   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);


Top
 Profile  
 
PostPosted: Wed Sep 19, 2012 7:33 pm 
Bibliotherapist
User avatar

Joined: Wed Nov 03, 2004 1:28 pm
Posts: 6719
Location: Oxford, Englandshire
A clipping plane is the point at which geometry stops being drawn, this is an optimisation to reduce the amount of drawing the GPU has to do.

The near clipping plane stops things behind the camera from being drawn (you'll never see them anyway), the sides of the view frustrum perform the same role for things that are outside the lateral field of view.

The far clipping plane is the point at which objects disappear from view. This has to be set carefully so things don't suddenly pop into view when moving towards the camera.

The location of the near and far clipping planes is a trade off between savings on rasteristation and providing a good view distance.

_________________
10 PRINT "Bad Monkey ";
20 GOTO 10


Top
 Profile  
 
PostPosted: Wed Sep 19, 2012 7:34 pm 
Bibliotherapist
User avatar

Joined: Wed Nov 03, 2004 1:28 pm
Posts: 6719
Location: Oxford, Englandshire
Oh, and looking at your code, you might be missing a call to glViewport().

Have you looked at the wiki samples?

http://content.gpwiki.org/index.php/Ope ... st_Polygon

_________________
10 PRINT "Bad Monkey ";
20 GOTO 10


Top
 Profile  
 
PostPosted: Wed Sep 19, 2012 7:42 pm 
Double Guru
User avatar

Joined: Fri Aug 12, 2005 8:58 am
Posts: 2009
Location: LA, CA
glOrtho is used for 2d, it basically makes everything flat (no Z depth). The left/right top/bottom are for mapping the screen. EX:
Code:
glOrtho(0.0f, screenWidth, 0.0f, screenHeight, 0.0f, 1.0f);

would make everything in pixel coordinates with the lower left being (0,0) and upper right being (screenWidth, screenHeight).

The clipping plane is a way to cull/not render items in the "scene". It basically says anything in front of the near plane and anything beyond the far plane are not going to be rendered.

_________________
My Development Blog | My Website | My Current 3d Engine


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group