c++ - GLUT is just rendering a blank white screen? -
here code, there aren't errors, wrong it?
i compile it, command prompt opens, window opens, window white, recolored grey.., , not draw shape, problem?
#ifdef __apple__ #include <glut/glut.h> #else #include <gl/glut.h> #endif #include <stdlib.h> void processspecialkeys(int key, int x, int y){ switch(key){ case glut_key_right: exit(0); case glut_key_left: exit(0); case glut_key_up: exit(0); case glut_key_down: exit(0); default: exit(0); } } void renderscene(void) { glclearcolor(0.3f, 0.3f, 0.3f, 0.3f); glclear(gl_color_buffer_bit | gl_depth_buffer_bit); glutswapbuffers(); } void renderprimitive(void){ glbegin(gl_quads); glvertex3f(-1.0f,-1.0f,0.0f); glvertex3f(-1.0f,1.0f,0.0f); glvertex3f(1.0f,1.0f,0.0f); glvertex3f(1.0f,-1.0f,0.0f); glend(); } void display(void){ gltranslatef(0.0f,0.0f,-0.5f); renderprimitive(); glflush(); glclearcolor(0.3f,0.3f,0.3f,0.3f); glclear(gl_color_buffer_bit); } int main(int argc, char **argv) { glutinit(&argc, argv); glutinitdisplaymode(glut_depth | glut_double | glut_rgba); glutinitwindowposition(100,100); glutinitwindowsize(320,320); glutcreatewindow("dimension"); glutdisplayfunc(display); glloadidentity(); glutspecialfunc(processspecialkeys); glutmainloop(); return 1; }
the problem clearing display after draw scene in display function. also, there useless glflush() call. remove these lines:
glflush(); glclearcolor(0.3f,0.3f,0.3f,0.3f); glclear(gl_color_buffer_bit); add glutswapbuffers() instead of them.
glflush() used in single buffered mode.
remember, using double buffered mode, there 2 buffers. scene drawn buffer, , display it, have copy front buffer calling glutswapbuffers() @ end of display function.
Comments
Post a Comment