Sorry, gonna post the code with some modifcations:
Basically, you forgot to go back to modelview after you had done the orthographic thing in init(). Also I made it double buffered.
Dont know about your crashes, works fine for me. (using ms vc++6). Maybe its a calling convention thing, atleast watcom uses register calling but glut wants stack based calling. That have caused troubles for me.
#include <windows.h> /* Windows Library /
#include <GL/gl.h> / OpenGL Library /
#include <GL/glut.h> / Glut Library /
#include <math.h> / Math Library */
int down = 0;
int true = 1;
int false = 0;
int mx,my;
void circle(int xcentre,int ycentre, float radius){
float angle, angle_increment;
float next_x,next_y;
int i;
angle_increment = (3.14159*2/100);
angle=0;
glBegin(GL_LINE_LOOP);
for (i=0; i<=100; i++){
angle = angle + angle_increment;
next_x = radius * cos(angle);
next_y = radius * sin(angle);
next_x = next_x + xcentre;
next_y = next_y + ycentre;
glVertex2f(next_x,next_y);
}
glEnd();
}
void mouse(int button, int state, int x, int y){
if (state == GLUT_UP)
down = false;
if (state == GLUT_DOWN)
down = true;
}
void display(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
circle(mx,400-my,10);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x, int y){
if (down == true){
mx=x;
my=y;
}
display();
}
void keyboard(unsigned char key, int x,int y){
if (key==‘r’)
glColor3f(1.0,0.0,0.0);
if (key==‘b’)
glColor3f(1.0,1.0,1.0);
}
/----------------------------------------------------------------------------------------------------------------------/
void init(void){
glClearColor(0.0,0.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 399.0, 0.0, 399.0, -100.0, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(400, 400);
glutInitWindowPosition(200, 200);
glutCreateWindow(“Vas Simple Paint Program”);
init();
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutKeyboardFunc(keyboard);
glutIdleFunc(display);
glutMainLoop();
return 0;
}