Hello Guest

Some questions about camera position

  • 2 Replies
  • 2028 Views
*

Offline @

  • *
  • 41
Some questions about camera position
« on: May 09, 2014, 08:35:18 »
Right now, this is how i have initialized opengl:

Quote
updateScreen();
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glClearColor(0.f, 0.f, 0.f, 1.f);

public void updateScreen() {      
   final int rw = (int) (Display.getWidth() / scale());
   final int rh = (int) (Display.getHeight() / scale());
      
   final float x = vx;
   final float y = vy;
   final float w = x + rw;
   final float h = y + rh;
   
   glViewport(0, 0, Display.getWidth(), Display.getHeight());
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(x, w, y, h, 1.f, -1.f);
   glMatrixMode(GL_MODELVIEW);
}

updateScreen is also use for whenever i move the camera. Now:

1)Is this code "good enough" ?
2)I wanted to move the camera using glulookat, but suddenly nothing appears on the screen. I read it is a common mistake, but i can't figure out how to fix it.

*

Offline Cornix

  • *****
  • 487
Re: Some questions about camera position
« Reply #1 on: May 09, 2014, 09:19:40 »
1) If you use ortho on the projection matrix you are using a 2D perspective.
2) GluLookAt is for 3D perspectives.
3) If you want to move a 2D camera you just translate the matrix along the X/Y-Axes.

*

Offline @

  • *
  • 41
Re: Some questions about camera position
« Reply #2 on: May 09, 2014, 17:12:08 »
Thanks cornix, then i suppose i leave it just like that.