1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#include <stdio.h> #include <stdlib.h> #include <GL/gl.h> #include <GL/glu.h> #include <GL/glut.h>
void RenderScene(void) {
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f,0.0f,0.0f);
glRectf(100.f,150.0f,150.0f,100.0f);
glFlush(); }
void SetupRC(void) { glClearColor(0.0f,0.0f,1.0f,1.0f); }
void ChangeSize(GLsizei w, GLsizei h) {
if(h == 0) h = 1;
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION); glLoadIdentity();
if(w <= h) glOrtho(0.0f,250.0f,0.0f,250.0f*h/w,1.0,-1.0); else glOrtho(0.0f,250.0f*w/h,0.0f,250.0f,1.0,-1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }
int main(int argc, char** argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutCreateWindow("Plot Rect. using GLUT"); glutDisplayFunc(RenderScene); glutReshapeFunc(ChangeSize); SetupRC(); glutMainLoop(); return (EXIT_SUCCESS); }
|