#114454 - Vich - Mon Jan 08, 2007 1:47 am
I'm having a problem with overlaying 2D over 3D in my application. I've tried to use my regular Windows/Linux OpenGL approach first, but that didn't work. I used Google and this forum's search but I couldn't really find NDS-OpenGL-related solutions, so this is what I do:
First I start a scene:
Then I push some triangles(a piramid) in 3D:
Then I init 2D mode:
Then I draw some 2D stuff:
Then I finish the 2D mode:
And finally I finish rendering:
Does anyone have an idea what I do wrong?
Is it correct to draw a 2D vertex by using glVertex3f(x, y, 0) or must it be glVertex3f(x, 0, z)? (by trying the second one, the application still gives me a wrong result.
Here's a screenshot of what is shown(updated!):
http://warehouse.lifeisdigital.net/pictures/other/dsguiproblem.png
I understand that there are other ways of overlaying 2D, but I only want to work with the OpenGL implementation that is provided through libnds.
Last edited by Vich on Mon Jan 08, 2007 11:14 am; edited 3 times in total
First I start a scene:
Code: |
void GraphicsBridgeOglNds::BeginScene(bool clearBackBuffer) { glReset(); gluPerspective(35.0f, 256.0f / 192.0f, 0.1f, 100.0f); glColor3f(1, 1, 1); glLight(0, RGB15(31,31,31) , 0, floattov10(-1.0f), 0); glMatrixMode(GL_TEXTURE); glIdentity(); glMatrixMode(GL_MODELVIEW); glIdentity(); glMaterialf(GL_AMBIENT, RGB15(16,16,16)); glMaterialf(GL_DIFFUSE, RGB15(16,16,16)); glMaterialf(GL_SPECULAR, BIT(15) | RGB15(8,8,8)); glMaterialf(GL_EMISSION, RGB15(16,16,16)); glMaterialShinyness(); glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE | POLY_FORMAT_LIGHT0); } |
Then I push some triangles(a piramid) in 3D:
Code: |
glPushMatrix(); glTranslate3f32(0, 0, floattof32(-4.0f)); glBegin(GL_TRIANGLES); // Push some vertices... glEnd(); glPopMatrix(1); |
Then I init 2D mode:
Code: |
void GraphicsOglNds::StartGuiViewMatrix() { glLoadIdentity(); ClearDepthBuffer(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, 256, 192, 0, 0, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glColor3f(1, 1, 1); glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE); SetOptionDepthTesting(false); } |
Then I draw some 2D stuff:
Code: |
glPushMatrix(); glTranslatef(0.0, 0.0, 0.0); glBegin(GL_QUADS); glVertex3f(-10.0, -10.0, 0.0); glVertex3f(10.0, -10.0, 0.0); glVertex3f(10.0, 10.0, 0.0); glVertex3f(-10.0, 10.0, 0.0); glEnd(); glPopMatrix(1); |
Then I finish the 2D mode:
Code: |
void GraphicsOglNds::EndGuiViewMatrix() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); SetOptionDepthTesting(true); SetOptionLighting(bPrevLightingState); } |
And finally I finish rendering:
Code: |
void GraphicsBridgeOglNds::EndScene() { glFlush(); swiWaitForVBlank(); } |
Does anyone have an idea what I do wrong?
Is it correct to draw a 2D vertex by using glVertex3f(x, y, 0) or must it be glVertex3f(x, 0, z)? (by trying the second one, the application still gives me a wrong result.
Here's a screenshot of what is shown(updated!):
http://warehouse.lifeisdigital.net/pictures/other/dsguiproblem.png
I understand that there are other ways of overlaying 2D, but I only want to work with the OpenGL implementation that is provided through libnds.
Last edited by Vich on Mon Jan 08, 2007 11:14 am; edited 3 times in total