I want to do something like this
for(int j = 0; j < 2000; j++)
{
for(int i = 0; i < 1000; i++)
{
x = some-value-by-calculation;//in my following whole src, I simpified this by only using random number,
y = some-value-by-calculation;//but the true value is not so
glVertex2f(x, y);
if esc-is-pressed the end-whole-program;// or menu later
if mouse-drag-window-corner then resize-window
}
}
but I don’t know where to put the kbd/mouse function, can anyone help? thanks. The whole code is:
#include <math.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
const int Wid = 640;
const int Hi = 480;
const float HalfWid=Wid*0.5;
const float HalfHi=Hi*0.5;
#define RAND (double(rand()-RAND_MAX/2)/(RAND_MAX/2))
void keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case 27:
exit(0);
break;
}
}
void update(void)
{
glutPostRedisplay(); // redisplay everything
}
void changeSize(int w, int h)
{
float ratio = ((float) w) / ((float) h); // window aspect ratio
glMatrixMode(GL_PROJECTION); // projection matrix is active
glLoadIdentity(); // reset the projection
gluPerspective(45.0, ratio, 1, 100.0); // perspective transformation
//glMatrixMode(GL_MODELVIEW); // return to modelview mode
glViewport(0, 0, w, h); // set viewport (drawing area) to entire window
glutPostRedisplay(); // redisplay everything
}
void myDisplay(void)
{
float x, y;
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
// Reset transformations
glLoadIdentity();
for(int j = 0; j < 2000; j++)
{
for(int i = 0; i < 1000; i++)
{
x = RAND;
y = RAND;
glBegin(GL_POINTS);
glColor3f(1.0, 0.5, 0.5);
glVertex2f(x, y);
glEnd();
glFlush();
glutSwapBuffers();
}
}
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(100, 100);
glutInitWindowSize(640, 480);
glutCreateWindow("");
glutKeyboardFunc(keyboard);
glutIdleFunc(update); // incremental update
glutReshapeFunc(changeSize); // window reshape callback
glutDisplayFunc(myDisplay);
glutMainLoop();
return 0;
}