| | |
OpenGL not depth buffering?
Thread Solved |
Hi, I've been testing GLFW joystick, trying to write a simple program to rotate a cube with the joystick. The fact that I'm using GLFW may complicate matters for debugging, but it's the only OpenGL library with joystick support that i have found. I don't believe that it should be simple to port to GLUT, just comment out the GLFW calls...
when i rotate the cube some faces obscure other faces regardless of which way they are facing. so i simplified to two quads, one in front, and one in back, and it exhibits the same problem, when rotated to 180 the front face is still drawn in front of the back face. the origin is centered between them.
if you have a joystick, the axes are off, i didn't match them yet. if you don't have a joystick the two faces will rotate about the y axis in an animation.
I think my code is missing something simple, but I can't seem to figure it out. the code isn't short, but I've posted longer...
when i rotate the cube some faces obscure other faces regardless of which way they are facing. so i simplified to two quads, one in front, and one in back, and it exhibits the same problem, when rotated to 180 the front face is still drawn in front of the back face. the origin is centered between them.
if you have a joystick, the axes are off, i didn't match them yet. if you don't have a joystick the two faces will rotate about the y axis in an animation.
I think my code is missing something simple, but I can't seem to figure it out. the code isn't short, but I've posted longer...
C Syntax (Toggle Plain Text)
#include <cstdlib> #include <stdlib.h> // For malloc() etc. #include <stdio.h> // For printf(), fopen() etc. #include <iostream> // For cout #include <math.h> // For sin(), cos() etc. #include <GL/glfw.h> // For GLFW, OpenGL and GL //For animation if no joystick is preasent. double angle=0.0; void Draw( void ){ int width, height; // Window dimensions double t; // Time (in seconds) // Get current time t = glfwGetTime(); // Get window size glfwGetWindowSize( &width, &height ); // Make sure that height is non-zero to avoid division by zero height = height < 1 ? 1 : height; // Set viewport glViewport( 0, 0, width, height ); // Clear color and depht buffers glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); //glClearDepth(-10000); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // Set up projection matrix glMatrixMode( GL_PROJECTION ); // Select projection matrix glLoadIdentity(); // Start with an identity matrix glOrtho(-2,2,-2,2,-2,2); // Set up modelview matrix glMatrixMode( GL_MODELVIEW ); // Select modelview matrix glLoadIdentity(); // Start with an identity matrix // glRotated(30,0,1,0); //glRotated(30,1,0,0); if(glfwGetJoystickParam(0,GLFW_PRESENT)){ float pos[4]; int num = glfwGetJoystickPos(GLFW_JOYSTICK_1,pos,10); float scale = ((-pos[2])+1)/2; glScalef(scale,scale,scale); if(!(pos[0]<0.05&&pos[0]>-0.05)){ glRotated(180*pos[0],1,0,0); } if(!(pos[1]<0.05&&pos[1]>-0.05)){ glRotated(180*pos[1],0,1,0); } if(num<3){ if(!(pos[3]<0.05&&pos[3]>-0.05)){ glRotated(180*pos[3],0,0,1); } } } else { glRotated(angle,0,1,0); angle=angle+1; } glBegin(GL_QUADS); glColor3f(1,0,0); glVertex3f(1,1,1); glVertex3f(-1,1,1); glVertex3f(-1,-1,1); glVertex3f(1,-1,1); glColor3f(0,1,0); glVertex3f(1,-1,-1); glVertex3f(-1,-1,-1); glVertex3f(-1,1,-1); glVertex3f(1,1,-1); /* glColor3f(0,0,1); glVertex3f(1,1,1); glVertex3f(1,1,1); glVertex3f(1,1,1); glVertex3f(1,1,1); glColor3f(1,1,0); glVertex3f(1,1,1); glVertex3f(1,1,1); glVertex3f(1,1,1); glVertex3f(1,1,1); glColor3f(1,0,1); glVertex3f(1,1,1); glVertex3f(1,1,1); glVertex3f(1,1,1); glVertex3f(1,1,1); glColor3f(0,1,1); glVertex3f(1,1,1); glVertex3f(1,1,1); glVertex3f(1,1,1); glVertex3f(1,1,1); */ glEnd(); glfwSwapBuffers(); } //---------------------------------------------------------------------- // main() - Program entry point //---------------------------------------------------------------------- int main( int argc, char **argv ) { int ok; // Flag telling if the window was opened int running; // Flag telling if the program is running // Initialize GLFW glfwInit(); glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_BUFFER_BIT); glDisable(GL_CULL_FACE); glCullFace(GL_BACK); //glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); // Open window ok = glfwOpenWindow( 640, 480, // Width and height of window 8, 8, 8, // Number of red, green, and blue bits for color buffer 8, // Number of bits for alpha buffer 24, // Number of bits for depth buffer (Z-buffer) 0, // Number of bits for stencil buffer GLFW_WINDOW // We want a desktop window (could be GLFW_FULLSCREEN) ); // If we could not open a window, exit now if( !ok ) { glfwTerminate(); return 0; } // Set window title glfwSetWindowTitle( "My OpenGL program" ); // Enable sticky keys glfwEnable( GLFW_STICKY_KEYS ); // Main rendering loop do { // Call our rendering function Draw(); // Check if the escape key was pressed, or if the window was closed running = !glfwGetKey( GLFW_KEY_ESC ) && glfwGetWindowParam( GLFW_OPENED ); } while( running ); // Terminate GLFW glfwTerminate(); // Exit program return 0; }
My site, random PM's from people I haven't hear from before will be DELETED
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "-Albert Einstein
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "-Albert Einstein
It seems that GLFW doesn't properly initialize the opengl state machine until you call glfwOpenWindow.
Move the call to glEnable ( GL_DEPTH_TEST ); to somewhere after the call to glfwOpenWindow. It should work then.
You don't need to call glEnable ( GL_DEPTH_BUFFER_BIT ), at best it's meaningless and at worst it's trying to enable something random.
Move the call to glEnable ( GL_DEPTH_TEST ); to somewhere after the call to glfwOpenWindow. It should work then.
You don't need to call glEnable ( GL_DEPTH_BUFFER_BIT ), at best it's meaningless and at worst it's trying to enable something random.
Plato forgot the nullahedron..
Thanks, that worked, was that something I missed in the GLFW documentation?
My site, random PM's from people I haven't hear from before will be DELETED
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "-Albert Einstein
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "-Albert Einstein
![]() |
Similar Threads
- Visual C++ Debugging Problem (C++)
- Audio trouble (PCI and Add-In Cards)
- Using OpenGL in Visual C++: Part I (Game Development)
- OpenGL (Game Development)
- Open Gl Programing Error (help)... (Game Development)
Other Threads in the Game Development Forum
- Previous Thread: i need help with making my game in DarkGDK
- Next Thread: gaming mods
| Thread Tools | Search this Thread |
3d advertising ai algorithm ban c++ cambridge camera censorship china competition console development engine fov fpx game gamer games gaming gauntanamo government idaho in-gameadvertisement intellectualproperty l-systems laracroft lindenmayer live manhunt math mathematics matrix mercenaries microsoft mmorpg modded msn naked news nintendo obama opengl palin physics pirate playstation politics projection ps3 rpg search selection software sony stephenhawking stocks studio technology terrorism tombraider uk videogame web wii world-of-warcraft xbox xbox-live xbox360






