Open GL pixel is not drawn on the screen

I’m noob in OpenGL and trying to implement a program as When a user clicks in the widow area a pixel should be drawn at that position. But the pixel is not drawn. If any body can help me then it would be great…Thank you :slight_smile:
Here is my code.


#include <iostream>
#include <GL/glut.h> 
int a,b;
using namespace std;

void display()
{
   glPointSize(20);
   glBegin(GL_POINTS);
   glColor3f(1.0,1.0,1.0);
   glVertex2f(a,b);
   glEnd();
   glFlush(); 
}

void mouse(int button,int state,int x,int y)
{
        switch(button)
        {
        case GLUT_LEFT_BUTTON:
                    a=x;
                    b=y;
                    glutPostRedisplay();    
                    return;
            case GLUT_RIGHT_BUTTON:
                return;
            default:
                break;
        }
}
int main(int argc,char** argv)
{

   glutInit(&argc,argv); 
   glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); 
   glutInitWindowSize(400,300); 
   glutInitWindowPosition(200,200); 
   glutCreateWindow("My First OpenGL");
   glutMouseFunc(mouse);
   glutDisplayFunc(display); 
   glutMainLoop();
   return 0; 
}

You do not set your modelview and projection matrices, so they are identity. When you call glVertex2f, everything outside [-1,+1] is outside the screen. The pixel positions you get in the mouse callback are in the range [0,399] and [0,299].

Okay…Thanks for the reply. As i am a noob in this i wasn’t knowing about it. Will correct it.

Also you need glBegin(GL_POINTS) glEnd() to bracket the glVertex call to let it known that you want to render individual pixels.