Open GL window - scale of things inside

Started by
2 comments, last by jag_oes 22 years, 3 months ago
Hello, I want to recreate a game I made for a class (had to be done in old, old turbo 3.0) in Open GL, but I am having a hard time getting the screen how I want it. I got the window to come up with the dimensions that I want (thanks to NeHe) but the inside is not scaled how I want it to be. To start off my drawing code I do this:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
 
I then use the glTranslatef function so that the origin is at the center of the screen and that the scale of 1.0f would be about a pixel in the screen (the screen being 400x400). So, I do something like this:

glTranslatef (0.0f, 0.0f, -100.0f);
 
At first I thought -100.0f would be far enough away, but it turns out that a line from (0,0) to (20,20) goes across about half the screen. So, I upped the last argument in the glTranslatef some to see if I could get the line look like it was really going 20 pixels along the x- and y-axis. But, whenever I put a number greater than 100 *nothing* appears ... it is like there is a limit on how far back you can go. Does anyone understand what I am talking about? Any solutions? Thanks
Advertisement
At the begging of your program set up ortho mode. (I am assuming you are doing 2d here)

glOrtho(0.0f,400,400,0.0f,-1.0f,1.0f);

0,0 will be the upper left corner, and 400,400 will be the bottom right.

I think thisis what you want.

--------------------------

Those who dance are considered insane by those who cannot hear the music.
Those who dance are considered insane by those who cannot hear the music.
Ok, thanks ... works nice. But, is there anyway to keep (0,0) at the center of the screen and preserve the y-axis being positive as it goes up?
Well the first 4 numbers entered into glOrtho are Left, Right, Bottom , Top.

So to get negative and positive y axis try
  glOrtho(-200, 200, -200, 200, -1, 1);  

That should place 0,0 in the center and both the x and y axis should go from -200 to +200.

Is that what you want?

"To err is human, to really mess up requires a computer"
"To err is human, to really mess up requires a computer"

This topic is closed to new replies.

Advertisement