View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# I need help drawing a square using SDL/Opengl.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1GDsnakes  Members

Posted 04 October 2012 - 07:49 AM

Ok, ignore the timer code, my problem is (that I cant seem to find a solution to after days of searching) is the drawing of the square.

You see how its a 0.5x0.5 square? Well its 0.5 of the screen. Run this code on your computer and see. IDK why its like this. If the screen size is 640x480 then shouldnt the square be very small on the screen? I dont want it to be 0.5 of the screens width/height but just 0.5 units long.

I've used freeglut and could draw squares fine without any problems. Now that I'm using SDL/Opengl together I have this problem.

When I change the screen size it changes the entire window size. When I draw a square thats 1.0x1.0 for example its not drawn as 1/the screens size, but as 1 = a whole. So the square thats 1x1 is automatically the entire screen regardless of its size and a square 0.5x0.5 is automatically half the screens size. I need to fix this.

### #2Brother Bob  Moderators

Posted 04 October 2012 - 08:01 AM

The modelview and projection matrices are both identity matrices, which means the visible coordinate range is from -1 to 1 along all axes. If you draw a quad that extends from -0.5 to 0.5, then, on a coordinate system that is from -1 to 1, you'll get a quad that is half the size of the screen.

If you want another coordinate system, then you have to set up another coordinate system as well. Look up glOrtho to begin with.

Edited by Brother Bob, 04 October 2012 - 08:02 AM.

### #3GDsnakes  Members

Posted 04 October 2012 - 08:08 AM

The modelview and projection matrices are both identity matrices, which means the visible coordinate range is from -1 to 1 along all axes. If you draw a quad that extends from -0.5 to 0.5, then, on a coordinate system that is from -1 to 1, you'll get a quad that is half the size of the screen.

If you want another coordinate system, then you have to set up another coordinate system as well. Look up glOrtho to begin with.

K, thank you. I'm new to all this. Still learning.

### #4GDsnakes  Members

Posted 04 October 2012 - 08:48 AM

How do I go about changing it from -1 to 1?

### #5Brother Bob  Moderators

Posted 04 October 2012 - 09:22 AM

That's what you do with glOrtho.

It takes, ignoring the two last ones for the moment, two pairs of parameters. First one is the horizontal range of the visible coordinate system (from left to right), and the second one is the vertical range of the visible coordinate system (from bottom to top).

If you want the visible coordinate system to range from left=0 to right=640 along the horizontal direction, and from bottom=0 to top=480 along the vertical direction, you call:
glOrtho(0, 640, 0, 480, -1, 1);


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.