1

When i try to run this code after compiling it, i got only a window border without content, so where is the error?

Note: i am using ubuntu and gcc for compiling

gcc -lglut Simple.c -o Simple 

The output

#include <GL/glut.h> // Header File For The GLUT Library #include <GL/gl.h> // Header File For The OpenGL Library #include <GL/glu.h> // Header File For The GLu Library void SetupRC(void); void RenderScene(void); void ChangeSize(GLsizei w, GLsizei h); // Called to draw scene void RenderScene(void) { // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT); // set the color to these values // R G B glColor3f(56.0f, 19.0f,68.0f); // Draw a filled rectangle with current color glRectf(-25.0f, 50.0f, 50.0f, -25.0f); // Flush drawing commands glFlush(); } int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA); glutInitWindowPosition(400,200); glutInitWindowSize(640,468); glutCreateWindow("Simple"); glutDisplayFunc(RenderScene); glutReshapeFunc(ChangeSize); SetupRC(); glutMainLoop(); return 0; } // Setup the rendering state void SetupRC(void) { glClearColor(0.0f, 2.0f, 1.0f, 0.0f); } // Handling window resizing void ChangeSize(GLsizei w, GLsizei h) { GLfloat aspectRatio; // Prevent divide by zero if (h == 0) h = 1; // Set Viewport to window dimensions glViewport(0, 0, w, h); // Reset coordinate system glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Establish clipping volume (left, right, bottom, top, near, far) aspectRatio = (GLfloat) w / (GLfloat) h; if (w <= h) { glOrtho(-100.0, 100.0, -100 / aspectRatio, 100.0 / aspectRatio, 1.0, -1.0); } else glOrtho(-100.0 * aspectRatio, 100.0 * aspectRatio, -100.0, 100.0, 1.0, -1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } 
6
  • 3
    Float colors go from 0.0 to 1.0. unsigned char 255 maps to float 1.0. That may help you some. Commented Feb 6, 2011 at 16:30
  • Thanks, i changed the values but it didn't help Commented Feb 6, 2011 at 16:39
  • 1
    Do you get nothing at all (black client area), or the cyan clear color and no box? The code works fine on my Ubuntu system with an Intel 4500MHD. What does glxinfo | grep renderer return? glxinfo is in mesa-utils. Commented Feb 6, 2011 at 18:19
  • The window is totally hidden but i see it when i toggle it and its content is the content behind it... bit.ly/eFNp5m the output is "OpenGL renderer string: Mesa DRI R300 (RS740 796E) 20090101 NO-TCL DRI2 " Commented Feb 6, 2011 at 20:44
  • try my output file on your machine mediafire.com/?4804oe8aagkus0o Commented Feb 6, 2011 at 20:47

2 Answers 2

2

Try adding a glutSwapBuffers() to the end of RenderScene().

Sign up to request clarification or add additional context in comments.

1 Comment

I think the problem is with my graphics card
0

One thing. You have a depth buffer so you should also add GL_DEPTH_BUFFER_BIT to the clear call.

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.