Reputation: 3946
Thanks to stack overflow I am very close to figuring out lots of problems I've been having. I got one more for this weekend.
I have an object called GameObject2D that is basically a square with some textures. Everything works when projecting this object in 3D. I use a method called prepare3Ddrawing to do this. I then want to do 2D drawing so I have a I am using a method to prep the projection matrix for 2d drawing. I've tried two different versions of the prepare2Ddrawing and can't seam to get it to work. First here is my 3d prep...
private void prepare3Ddrawing(GL10 gl)
{
gl.glLoadIdentity();
gl.glViewport(0, 0, getWidth(), getHeight());
gl.glDisable(GL10.GL_DITHER);
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
GLU.gluPerspective(gl, 45.0f, (float)getWidth()/(float)getHeight(),0.1f,100.0f);
}
And here is the version of my 2D that puts the origin at the bottom left instead of the top left...
private void prepare2Ddrawing(GL10 gl)
{
gl.glDisable(GL10.GL_DEPTH_TEST);
gl.glLoadIdentity();
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
GLU.gluOrtho2D(gl,0,getWidth(), 0, getHeight());
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
}
I believe I need the right combination of GLU.gluOrtho2D(gl...) to get the right result. Any ideas? Thanks!
Upvotes: 1
Views: 557
Reputation: 16774
GLU.gluOrtho2D(gl,0,getWidth(), 0, getHeight()) has parameters left, right, bottom, top. If you want "screen-like" coordinates you need to set top to "0.0" and bottom to "getHeight()". This method is basically used to setup your coordinate system. For instance, if you need to draw some graph you would want the (0,0) in center, left if (-1,0) and top is (0,1) so the parameters would be (-1, 1,-1, 1) but if you want to have something like most common screen coordinate system you will want to have (0,0) in top left corner and (width, height) in bottom right corner (0, width, height, 0). Or for the sake of simplicity: Just insert the coordinates you want at top-left and bottom-right points of your view.
Upvotes: 1