Problem mit glEnable(GL_DEPTH_TEST);
-
sobald ich GL_DEPTH_TEST aktiviere wird garnichts mehr gerendert, ausser ganz kurz am Anfang mal etwas und so ein Paar überreste der kanten. Ich hab schon alle parameter von glDepthFunc getestet, da ändert sich auch nichts, ausser bei GL_ALWAYS, da ist es wieder wie ohne GL_DEPTH_TEST. glDepthRange habe ich schon auf (-1000,1000) gestellt, um herauszufinden, ob es daran liegt, dass vieleicht der bereich zu klein ist, in dem die Tiefe bestimmt wird (oder hab ich den sinn diers dingens falsch verstanden).
#include <iostream> #include <GL/glfw.h> #include "functions.h" using namespace std; int running = GL_TRUE; void createBox(GLfloat size=1){ glBegin(GL_QUAD_STRIP); glColor3f(0,0,1); glVertex3f( 1.0f, 1.0f,-1.0f ); glVertex3f( 1.0f, 1.0f, 1.0f ); glVertex3f(-1.0f, 1.0f,-1.0f ); glVertex3f(-1.0f, 1.0f, 1.0f ); glColor3f(1,1,1); glVertex3f(-1.0f,-1.0f,-1.0f ); glVertex3f(-1.0f,-1.0f, 1.0f ); glColor3f(1,0,0); glVertex3f( 1.0f,-1.0f,-1.0f ); glVertex3f( 1.0f,-1.0f, 1.0f ); glColor3f(0,0,0); glVertex3f( 1.0f, 1.0f,-1.0f ); glVertex3f( 1.0f, 1.0f, 1.0f ); glEnd(); glBegin(GL_QUADS); glColor3f(0,1,0); glVertex3f( 1.0f,-1.0f, 1.0f ); glVertex3f( 1.0f, 1.0f, 1.0f ); glVertex3f(-1.0f, 1.0f, 1.0f ); glVertex3f(-1.0f,-1.0f, 1.0f ); glColor3f(1,0,1); glVertex3f( 1.0f, 1.0f,-1.0f ); glVertex3f(-1.0f, 1.0f,-1.0f ); glVertex3f(-1.0f,-1.0f,-1.0f ); glVertex3f( 1.0f,-1.0f,-1.0f ); glEnd(); } int main() { init(); glfwSetWindowSizeCallback( reshape ); glfwSetKeyCallback( key ); int box1 = glGenLists(1); glNewList(box1, GL_COMPILE); //glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red); createBox(); glEndList(); while(running){ running = glfwGetWindowParam( GLFW_OPENED ); glClear( GL_COLOR_BUFFER_BIT); glRotatef(.1,1,1,1); glPushMatrix(); //glTranslatef(-3.0, -2.0, 0.0); //glRotatef(angle, 0.0, 0.0, 1.0); glCallList(box1); glPopMatrix(); glfwSwapBuffers(); } glfwTerminate(); return 0; }#ifndef FUNCTIONS_H #define FUNCTIONS_H #include <GL/glfw.h> extern int running; extern float speed; void GLFWCALL reshape( int width, int height ); void GLFWCALL key( int k, int action ); bool init(void); void animate(); #endif // FUNCTIONS_H#include "functions.h" #include <iostream> using namespace std; bool init(void){ glfwInit(); if ( !glfwOpenWindow( 640, 480, 0, 0, 0, 0, 0, 0, GLFW_WINDOW ) ){ glfwTerminate(); running = GL_FALSE; return false; } glfwSetWindowTitle( "alles futsch und kaputt" ); //Hier hab ich einiges ausprobiert auskommentiert einkommentiert etc //Aber ich hab leider noch nicht so die Ahnung, was es eigentlich bedeutet glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glDepthRange(-10000,10000); glEnable(GL_CULL_FACE); //glEnable (GL_BLEND); glEnable (GL_NORMALIZE); //glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); //glOrtho(-5.0f, 5.0f, -5.0f, 5.0f,-1,1); return true; } void GLFWCALL reshape( int width, int height ){ cout << "reshape " << width << "x" << height <<endl; glViewport( 0, 0, (GLint) width, (GLint) height ); glLoadIdentity(); GLfloat f = (GLfloat)width/(GLfloat)height; glOrtho(-5.0f*f, 5.0f*f, -5.0f, 5.0f,-2,2); } void GLFWCALL key( int k, int action ){ if( action != GLFW_PRESS ) return; cout << "Tastendruck: "; switch (k) { case GLFW_KEY_ESC: running = 0; cout << "ESC" << endl; break; default: cout << endl; return; } }Also für mich ist OpenGL noch recht verwirrend, also kann es gut sein, dass ich einige strukturfehler habe, aber ich hoffe, dass ich das mit den Matrixteildingern richtig verstanden habe.
-
ok hab das Problem beheben können, hatte keinen GL_DEPTH_BUFFER_BIT bei glClear gesetzt, somit war sehr schnell alles weg.