PDA

View Full Version : Open GL pixel is not drawn on the screen



Hardik Modha
10-09-2014, 10:09 PM
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 :)
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;
}

Agent D
10-10-2014, 09:11 AM
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].

Hardik Modha
10-10-2014, 10:32 PM
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.

sueyllam
10-11-2014, 07:52 PM
Also you need glBegin(GL_POINTS) glEnd() to bracket the glVertex call to let it known that you want to render individual pixels.