Switching from 2D to 3D for drawing object

This topic is 2543 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

So for my inventory system, i want users to be able to see what the item looks like in the game. i tried using:

 glMatrixMode(GL_PROJECTION); glMatrixMode(GL_MODELVIEW); glDepthFunc(GL_LEQUAL); glDepthMask(GL_TRUE); glClear(GL_DEPTH_BUFFER_BIT); MainScreen.ShowItem3D.rots[0].ry=MainScreen.ShowRotY; MainScreen.ShowItem3D.Draw(0,0,0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, ScreenW, ScreenH, 0.0, -1.0, 10.0); glMatrixMode(GL_MODELVIEW); glDisable(GL_CULL_FACE); glClear(GL_DEPTH_BUFFER_BIT); glEnable(GL_TEXTURE_2D); 

Which the .Draw() would work where im usually drawing the in-game stuff, but for some reason it wont draw here. What might i be doing wrong?

Share on other sites
Hi,

A few weeks ago I was messing with the same stuff, you can get a working example in here(sorry for all the messy code, hope it's useful). Basically your display function will look something like this.

 void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // you can get the width and height using glutGet(GLUT_WINDOW_WIDTH) or HEIGHT height = height==0 ? 1 : height; float ratio = width * 1.0 / height; // dibujado en 3D glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, ratio, .1f, 1000.0f); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); gluLookAt( eyex, eyex, eyez, centerx, centery, centerz, upx, upy, upz ); glPushMatrix(); { // draw 3D things in here } glPopMatrix(); // 2D drawing glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, width, height, 0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glPushMatrix(); { // draw 2D things in here } glPopMatrix(); glutSwapBuffers(); } 

Share on other sites
Actually, i know what i need to do now. its the 2D Quads that get in the way. im trying to draw the 3D models, but the GUI quads are in front of them. How would i draw the depth-tested model infront of the quads?

Share on other sites
You could draw the model to a texture, and then render that texture as a 2D quad in your GUI. Or you could position the model so it's actually in front of the quad.

Share on other sites
How would i draw it to a quad then draw that texture? i think it would be easier to position it, if somehow the gui were to become just a color buffer, and the model uses both color and z buffer...

Share on other sites
Research 'render to texture' - the idea is simple: create a render target, draw to it, then bind that target as a texture when drawing to your main render target

Share on other sites
I dont think the idea needs to be that complicated. i just need to have the gui become a color only buffer so i can use the depth buffer for the model.

Share on other sites
unless you can post some code on how to do that, then i will try to do that.

http://www.opengl.or...ebuffer_Objects

Share on other sites

i just need to have the gui become a color only buffer so i can use the depth buffer for the model.

Then just disable depth write while drawing gui ( glDepthMask(GL_FALSE); )

1. 1
2. 2
Rutin
21
3. 3
4. 4
A4L
15
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 44
• Forum Statistics

• Total Topics
633742
• Total Posts
3013636
×