Advertisement

RenderScene() doesn't render

Started by November 06, 2004 01:01 PM
6 comments, last by Jiroh 20 years ago
Shouldn't this render a triangle?
#include <OpenGL/gl.h>          // Header File For The OpenGL32 Library
#include <OpenGL/glu.h>         // Header File For The GLu32 Library
#include <GLUT/glut.h>          // Header File For The GLut Library

#define kWindowWidth    640 
#define kWindowHeight   480

// Function Prototypes
GLvoid InitGL(GLvoid);
GLvoid DrawGLScene(GLvoid);
GLvoid ReSizeGLScene(int Width, int Height);
void glEnable2D();
void glDisable2D();
void RenderScene();

int main(int argc, char** argv)
{
        glutInit(&argc, argv);
        glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
        glutInitWindowSize (kWindowWidth, kWindowHeight);
        glutInitWindowPosition (100, 100);
        glutCreateWindow (argv[0]);

        InitGL();

        glutDisplayFunc(DrawGLScene);
        glutReshapeFunc(ReSizeGLScene);

        glutMainLoop();
		RenderScene();

        return 0;
}

GLvoid DrawGLScene(GLvoid){}
GLvoid InitGL(GLvoid){}

GLvoid ReSizeGLScene(int Width, int Height)
{}
void glEnable2D()
{
   int vPort[4];

   glGetIntegerv(GL_VIEWPORT, vPort);

   glMatrixMode(GL_PROJECTION);
   glPushMatrix();
   glLoadIdentity();

   glOrtho(vPort[0], vPort[0]+vPort[2], vPort[1], vPort[1]+vPort[3], -1, 1);
   glMatrixMode(GL_MODELVIEW);
   glPushMatrix();
   glLoadIdentity();
   glTranslatef(0.375, 0.375, 0.);

   glPushAttrib(GL_DEPTH_BUFFER_BIT);
   glDisable(GL_DEPTH_TEST);
}

void glDisable2D()
{
   glPopAttrib();
   glMatrixMode(GL_PROJECTION);
   glPopMatrix();   
   glMatrixMode(GL_MODELVIEW);
   glPopMatrix();       
}

void RenderScene()
{
  glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
  glLoadIdentity();
  
  glEnable2D();
    glBegin(GL_TRIANGLES);
      glColor3ub(255, 0, 0);
        glVertex2d(0, 0);
      glColor3ub(0, 255, 0);
        glVertex2d(100,0);
      glColor3ub(0, 0, 255);
        glVertex2D(50, 50);
    glEnd();
  glDisable2D();
}
  
I'm not really sure what I am missing. I'm compiling on XCode 1.2, Mac OS X 10.3.6
Since you're using double buffering, you need to swap the buffers. Add the function call glutSwapBuffers() to the end of your RenderScene function.
Advertisement
Hi, I added what you said, but still no triangle, unless it is rendering a white triangle on a white background.

These are the warnings I am getting:

1) Passing arg 2 of glGetIntegerv from incompatible pointer type

2) implicit declaration of function 'glVertex2D'

Following your instructions the RenderScene() is now:

void RenderScene(){  glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);  glLoadIdentity();    glEnable2D();    glBegin(GL_TRIANGLES);      glColor3ub(255, 0, 0);        glVertex2d(0, 0);      glColor3ub(0, 255, 0);        glVertex2d(100,0);      glColor3ub(0, 0, 255);        glVertex2D(50, 50);    glEnd();  glDisable2D();  glutSwapBuffers();}  
Try calling RenderScene() in your DrawGLScene() function, because that's the display callback you told GLUT to use while in the glutMainLoop(). If I remember correctly, there is no need to call RenderScene() after glutMainLoop() because the later will only return execution when the window is destroyed.
The second warning refers to your calling glVertex2D (as opposed to glVertex2d, remember C/C++ are case-sensitive). This is certainly something to fix. The first warning is referring to using int instead of GLint.

Edit: And aldenar is right ( I wasn't paying attention). You should call RenderScene() in DrawGLScene, and remove the glutSwapBuffers from the RenderScene, and replace it in DrawGLScene.
Ok, doing that I get

Zerolink: unknown symbol '_glVertex2D'

App has exited due to signal 6 (SIGABRT)

GLvoid DrawGLScene(GLvoid)
{
RenderScene();
}


Advertisement
Quote: Original post by Jiroh
Ok, doing that I get

Zerolink: unknown symbol '_glVertex2D'

App has exited due to signal 6 (SIGABRT)

GLvoid DrawGLScene(GLvoid)
{
RenderScene();
}


All of the calls should be glVertex2d, not glVertex2D
Hi, thanks for the tips. It now renders a triangle at the bottom left corner of screen.

So that much is cool, I now need to understand this code. Maybe I can alter it to change the trianle shape and position.

Thanks!

This topic is closed to new replies.

Advertisement