Jump to content
  • Advertisement
Sign in to follow this  
BennettSteele

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

Can you elaborate on what this means?

"

i just need to have the gui become a color only buffer"




[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]What is it, if not a color buffer?[/font]




[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]opengl render to texture (I don't see how this is "that complicated" - it's just simple compositing): [/font]


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

Share this post


Link to post
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); )

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!