Nice setup

Hi,

I’m sure that a lot of you don’t recode your ‘setup’ for your JoGL/OpenGL programs (such as the Viewport, Frustum, gluLookAt, etc…) everytime – so, I was hoping that someone could provide me with a nice little setup, for 3D apps?

Because, the setups that I make, they start to look okay… until I do something, such as rotate it, or some other transformation… in which, I get strange results, etc…

So, anyone provide a nice little setup please? :slight_smile:

Another thing: is it possible to configure it so that you can specify the dimensions and points in terms of pixels? For example, a single unit on my typicaly setup, takes up about 50+ pixels! Is there a way (in 3D) so that the dimensions are in terms of pixels?

Thanks!
Rob.

It really depends on what you want to do. DOoyou want a 3D environment or a blank 2D canvas to paint on. Do you want to manipulate a model in 3D Space or do you just want an orthogonal view (like if you’re doing an architectural drawing). I suggest you get yourself a copy of the redbook and set up a class of your own. Its the only way you’ll learn.

Regarding your second question: yes you can indeed, by using a orthogonal viewport based on the dimensions of your window. If you’re looking for tutorials I suggest you go check out http://nehe.gamedev.net that should get you started.

There are two ways to make 1 unit = 1 pixel:

  1. Use Ortho mode.
  2. Do this:
 
public static void initGL()
{
   GL11.glEnable(GL11.GL_TEXTURE_2D);
   ...
   // More enabling/disabling junk	
   ...	
   GL11.glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());				
   GL11.glMatrixMode(GL11.GL_PROJECTION); 
   GL11.glLoadIdentity(); 
   GL11.glFrustum(
	-Display.getDisplayMode().getWidth() / 64.0,
	Display.getDisplayMode().getWidth() / 64.0,
	-Display.getDisplayMode().getHeight() / 64.0,
	Display.getDisplayMode().getHeight() / 64.0,
	8,
	65536); 
    GL11.glMatrixMode(GL11.GL_MODELVIEW);        
}

What this does is make 1 OpenGL unit = 1 pixel at a depth of -256.0f. It also sets the center of the screen as (0, 0).
So, if you’re resolution is 800x600, to draw a quad the size of the screen you’d do:


GL11.glBegin(GL11.GL_QUADS);
   GL11.glVertex3f(-400, 300, 0.0f); 
   GL11.glVertex3f( 400, 300, 0.0f);
   GL11.glVertex3f( 400, -300, 0.0f);
   GL11.glVertex3f(-400, -300, 0.0f);
GL11.glEnd();

Anyway, this will get you what you want. The math in glFrustrum was taken from a post by princec. He said it was up for grabs, so I’m just recycling it.