philae
10-08-2009, 01:52 PM
I'm reaaly a newbie to openGL:) Here I wrote a code that opens a window of 500*500 , when the user clicks the window it draws a point.Here's the code and it doesn't work:
#include <GL/glut.h>
#include <GL/gl.h>
#include <iostream>
using namespace std;
void drawPoint(int x, int y) {
x = x - 250;
y = 250-y;
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0,0.0,1.0);
glPointSize(10);
glBegin(GL_POINTS);
glVertex2f(x , y);
glEnd();
glFlush();
}
void mouse(int bin, int state , int x , int y) {
if(bin == GLUT_LEFT_BUTTON && state == GLUT_DOWN) drawPoint(x,y);
}
void display (void){}
void init (void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glFlush();
}
int main (int argc,char** argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("My Window");
glutMouseFunc(mouse);
glutMotionFunc(drawSquare);
glutDisplayFunc(display);
init();
glutMainLoop();
return 0;
}
I don't understand why it doesn't work.It creates the window, gets the coordinates of the point under the marker but it doesn't draw the point.Can anyone help??Any help would be appreciated.I also wonder one more thing.Say , I manage to draw the points how can I delete them? Maybe I can draw point with background-color onto the old point , but what if I wanna delete a line?
#include <GL/glut.h>
#include <GL/gl.h>
#include <iostream>
using namespace std;
void drawPoint(int x, int y) {
x = x - 250;
y = 250-y;
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0,0.0,1.0);
glPointSize(10);
glBegin(GL_POINTS);
glVertex2f(x , y);
glEnd();
glFlush();
}
void mouse(int bin, int state , int x , int y) {
if(bin == GLUT_LEFT_BUTTON && state == GLUT_DOWN) drawPoint(x,y);
}
void display (void){}
void init (void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glFlush();
}
int main (int argc,char** argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("My Window");
glutMouseFunc(mouse);
glutMotionFunc(drawSquare);
glutDisplayFunc(display);
init();
glutMainLoop();
return 0;
}
I don't understand why it doesn't work.It creates the window, gets the coordinates of the point under the marker but it doesn't draw the point.Can anyone help??Any help would be appreciated.I also wonder one more thing.Say , I manage to draw the points how can I delete them? Maybe I can draw point with background-color onto the old point , but what if I wanna delete a line?