#### Archived

This topic is now archived and is closed to further replies.

# Open GL window - scale of things inside

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

## Recommended Posts

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);

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

##### Share on other sites
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.

##### Share on other sites
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?

##### Share on other sites
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"

• 11
• 20
• 12
• 10
• 37
• ### Forum Statistics

• Total Topics
631400
• Total Posts
2999860
×