Jump to content
  • Advertisement
Sign in to follow this  
sssss

OpenGL Problem when enabling GL_DEPTH_TEST

This topic is 2950 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

Hi guys i have some problems when drawing some 3D lines linked with nodes(pathfinding), im using OPENGL+SDL

here is the code

//OPENGL STUFF
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(-0.5f,-0.75f,0.0f);
glPushMatrix();
glPointSize(15.0f);
glScalef(0.25f,0.25f,1.0f);
drawNodesAndLines(help);
pathNodes.push_back(start);
if(pathNodes.size()>=1){
drawNodesAndLinesNoLink(pathNodes);
}
glPopMatrix();
SDL_GL_SwapBuffers();
//
// Init Gl
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport (0, 0, XSIZE, YSIZE);
gluPerspective (45, (GLfloat)(XSIZE / YSIZE), 1.0, 1000.0);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_POINT_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//
//Init SDL
if(SDL_Init(SDL_INIT_EVERYTHING)==-1) cout<<"BAD"<<endl;
screen=SDL_SetVideoMode(XSIZE,YSIZE,SCREEN_BPP,SDL_OPENGL | SDL_DOUBLEBUF);
SDL_WM_SetCaption("NODES",NULL);
//


When i dont enable GL_DEPTH_TEST it draws all the nodes, with their proper lines, and the nodes which form part of the pathfinding, are linked with white lines

When i enable GL_DEPTH_TEST it only draws the node with their linked lines, there is no way of seeing the white lines

Anyone knows what is happening??

Thanks

Share this post


Link to post
Share on other sites
Advertisement
//drawNodesandLines
void drawNodesAndLines(vector<Node*> &a){
vector<Node*> linked;
for(int i=0;i<a.size();i++){
linked=a->getNodesLinked();
drawNode(a);
for(int j=0;j<linked.size();j++){
drawLine(a,linked[j]);
}
}
}
void drawNodesAndLinesNoLink(vector<Node*> &a){
for(int i=0;i<a.size()-1;i++){
drawLinePath(a,a[i+1]);
}
}
//
//Draw stuff
void drawNode(Node* a){
glBegin(GL_POINTS);
glColor3f(0.5f,0.8f,1.0f);
glVertex3f(a->getPosition().x,a->getPosition().y,a->getPosition().z);
glEnd();
}

void drawLine(Node* a,Node* b){
glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_LINES);
glVertex3f(a->getPosition().x,a->getPosition().y,a->getPosition().z);
glVertex3f(b->getPosition().x,b->getPosition().y,b->getPosition().z);
glEnd();

}
void drawLinePath(Node* a,Node* b){
glColor3f(1.0f,1.0f,1.0f);
glBegin(GL_LINES);
glVertex3f(a->getPosition().x,a->getPosition().y,a->getPosition().z);
glVertex3f(b->getPosition().x,b->getPosition().y,b->getPosition().z);
glEnd();
}
//


Anyone knows a good tutorial of using cameras in opengl please??

Share this post


Link to post
Share on other sites
Eh, you probably spawn white lines on the same position as red lines and when u use depth Test it doesn't t meter which you render first

Nehe has got good enough tutorial for gluLookAt

And sth from me: stop using glBegin and glEnd only try to use display list >>> vertex pointers >>> VBO

Share this post


Link to post
Share on other sites
this is the problem, i draw white lines on top of the red ones, so the depth test doesnt know which one choose, is there any way of saying the depth test, that there is a white line, instead of the red??


i would kinda like to use vertex pointes a VBO but i have no idea of doing it, i need a way ok knowing how to start with 3d graphics, but i dont know how to start with it

Share this post


Link to post
Share on other sites
You just have to draw red line OR(^) white line. It depends of your implementation in c++. You can check for example if you will render white line and then u will not render red line. This problem is some kind of z-fighting.


So u should try display list because u do the same as in glbegin glend.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!