Question

I used a book called Computer Graphices using OpenGL.

at page number 51 i found this code

#include <windows.h>
#include "glut.h" 

//<<<<<<<<<<<<<<<<< method(s) >>>>>>>>>>>>>>>>>>>
void My_Display(void); 
void My_Inti(void); 

//<<<<<<<<<<<<<<<<< main method >>>>>>>>>>>>>>>>>>
int main(int argc, char ** argv)
{
    glutInit(&argc, argv); 
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); 
    glutInitWindowSize(640, 480); 
    glutInitWindowPosition(100, 150); 
    glutCreateWindow("my second try "); 
    glutDisplayFunc(My_Display);

    My_Inti(); 
    glutMainLoop(); 



    return 0;
}

//<<<<<<<<<<<<<<<<<<<<<<<< IMPLEMENTING METHOD(S) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.

//<<<<<<<<<<<<<<<< My_Inti >>>>>>>>>>>>>>>>>>>>>>>>>
void My_Inti(void)
{
    glClearColor(1, 1, 1, 0); // white color 
    glColor3f(0, 0, 0); // Black color 
    glPointSize(10); // point size is 10 pixel this is big .
    glMatrixMode(GL_PROJECTION);  
    glLoadIdentity(); 
    gluOrtho2D(0, 640, 0, 480); 
}


//<<<<<<<<<<<<<<<< My_Display >>>>>>>>>>>>>>>>>>>>>>
void My_Display(void)
{
    glClear(GL_COLOR_BUFFER_BIT); 
    glBegin(GL_POINT);
    glVertex2i(100, 50);
    glVertex2i(100, 130);
    glVertex2i(150, 130); 
    glEnd();
    glFlush();
}

all what i add to this code is the comments and i change a little at the variable ; nothing more .

When we come to the problem this code work fine but it didn't creat the three points at the display method ?

Was it helpful?

Solution

The problem is just one missing letter. Instead of this:

glBegin(GL_POINT);

The correct value is:

glBegin(GL_POINTS);

The first thing I would do any time you get no rendering, or not the expected rendering, is to call glGetError(), and see if it returns an error. I admit that I didn't see this problem initially, but calling glGetError() would have pointed it out quickly.

BTW: In case anybody else is surprised that there are both GL_POINT and GL_POINTS enums in OpenGL. GL_POINT is one of the possible arguments to glPolygonMode(), as opposed to GL_POINTS which denotes one of the possible primitive types for draw calls.

OTHER TIPS

It does not work because there is an error in the source code (unlikely) or you mis-copied the argument for glBegin(GL_POINT); (likely).

Using

glBegin(GL_POINTS);

I got this image:

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top