hithere
hithere

Reputation: 520

OpenGL Orthographic View App Windowed-to-Fullscreen

I'm working on a tile-based 2D OpenGL game (top down, 2D Zelda style), and I'm using an orthographic projection. I'd like to make this game both windowed and fullscreen compatible.

Am I better off creating scaling 2D drawing functions so that tile sizes can be scaled up when they're drawn in fullscreen mode, or should I just design the game fully around windowed mode and then scale up the ENTIRE drawing area whenever a player is in fullscreen mode?

In the end, I'm hoping to maintain the best looking texture quality when my tiles are re-scaled.

UPDATE/CLARIFICATION: Here's my concern (which may or may not even be a real problem): If I draw the entire windowed-view-sized canvas area and then scale it up, am I potentially scaling down originally 128x128 px textures to 64x64 px windowed-sized textures and then re-scaling them up again to 80x80 when I scale the entire game area up for a full screen view?

Other background info: I'm making this game using Java/LWJGL and I'm drawing with OpenGL 1.1 functions.

Upvotes: 2

Views: 1377

Answers (1)

Luca
Luca

Reputation: 11961

Dont scale tiles because your fullscreen window is larger than the normal one, but play with the projection matrix.

The window is getting larger? Enlarge the parameters used for constructing the projection matrix.

If you want to mantain proportional the tile size respect the window size, don't change projection matrix depending on window size!

The key is, if you haven't catched yet, the projectiona matrix: thanks to it, vertices are projected onto the viewport, indeed vertices are "scaled", letting you to choose appropriate unit system without worring about scaling.


In few words, the orthographic projection is specified from 4 parameters: left, right, bottom and top. Those parameters are nothing but the XY coordinates of the vertex projected onto the window screen boundaries (really the viewport).

Let do some concrete example.

Example 1

Window size: 400x300

OpenGL vertex position (2D): 25x25

Orthographic projection matrix: - Left= 0 - Right= 400 - Bottom= 0 - Top= 300

Model view matrix set to identity

--> Point will be drawn at 25x25 in window coordinates

Example 2

Window size: 800x600 (doubled w.r.t example 1)

OpenGL vertex position (2D): 25x25

Orthographic projection matrix: - Left= 0 - Right= 400 - Bottom= 0 - Top= 300

Model view matrix set to identity

--> Point will be drawn at 50x50 in window coordinates. It is doubled because the orthographic projection haven't changed.

Example 3

Let say I want to project the vertex in example 1 even if the aspect ratio of the window changes. Previous windows were 4:3. The window in this example is 16:9: it is larger! The trick here is to force the ratio between (right - left) and (top - bottom)

Window size: 1600x900 (doubled w.r.t example 1)

OpenGL vertex position (2D): 25x25

Orthographic projection matrix:

  • Left= 0
  • Right= 533 (300 * 16 / 9)
  • Bottom= 0
  • Top= 300

Model view matrix set to identity

--> Point will be drawn at 25x25 (instead of 33.3x25, if we were using the projection matrix of the example 1) in window coordinates.

Upvotes: 4

Related Questions