Hello Guest

Window-to-viewport mapping

  • 3 Replies
  • 9720 Views
*

Offline appel

  • *
  • 18
Window-to-viewport mapping
« on: October 03, 2006, 05:10:37 »
I'm going nuts over this, but I'm studying OpenGL, and this book I have isn't doing a good job explaining this to me.

All I need actually is verification, I know how to do this mapping, but I just need to know what actually happens!

Little definition first;

(this is a 2D scenario)

World = Everything in the game, based on X,Y cartesian axes.

World-Window = What part of the World is being displayed from P1=(x1,y1) through P2=(x2,y2).

Viewport = Defines how the World-Window is displayed.


Everything in the world-window gets stretched to fit whatever size viewport is defined as.

I made a image:



Am I correct about this?

*

Offline appel

  • *
  • 18
Window-to-viewport mapping
« Reply #1 on: October 03, 2006, 05:54:42 »
Kevglass verified to me that I am correct.

But, I'm trying to accomplish this in lwjgl.

What I'm doing is;

drawing a polygon (rectangle) that is 10x10, and has the origin point 0,0.

I have defined:
GL11.glOrtho(0, 10, 0, 10, -1, 1);
GL11.glViewport(0,640,0,480);

Shouldn't that polygon fill the window? (the window is 640x480).

Nothing happens :\


my code is here: http://www.private.is/arni/OpenGL.java

hmmmmmmm...
« Reply #2 on: October 03, 2006, 14:50:57 »
One thing you might try, is to do GL_QUADS or GL_TRIANGLES instead of GL_POLYGON.
Also its possible that the polygon you are drawing is getting culled (not drawn because its facing the wrong way). Try drawing the polygon in the reverse order. I can't remember if OpenGL defaults to clockwise or counter-clockwise front face.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

*

Offline appel

  • *
  • 18
Window-to-viewport mapping
« Reply #3 on: October 03, 2006, 17:10:28 »
Kevglass gave me the solution;

Code: [Select]
GL11.glViewport(0,0,640,480);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, 10, 10, 0, -1, 1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();