OpenGL-1
Anindo
c_cpp
a year ago
2.7 kB
3
Indexable
Never
#include<windows.h> #include <GL/glut.h> #include <GL/gl.h> #include <math.h> #define PI 3.1416 static float tx = 0.0; static float ty = 0.0; void circle(float radius_x, float radius_y) { int i=0; float angle = 0.0; glBegin(GL_POLYGON); for(i = 0; i < 100; i++) { angle = 2 * PI * i / 100; //glVertex2f (cos(angle) * radius_x, sin(angle) * radius_y); glVertex2f (cos(angle) * radius_x+0.8, sin(angle) * radius_y+0.8); } glEnd(); } void initGL() { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //background clear glOrtho(-1,1,-1,1,-1,1); } /* void triangle() { glBegin(GL_TRIANGLES); glVertex2f(0.3f, 0.5f); glVertex2f(0.5f, 0.7f); glVertex2f(0.7f, 0.5f); glEnd(); } */ void display() { glClear(GL_COLOR_BUFFER_BIT);// Buffer CLear glBegin(GL_LINES); glColor3f(1.0,1.0,1.0); glVertex2f(-100,0); glVertex2f(100,0); glVertex2f(0,-100); glVertex2f(0,100); glEnd(); //triangle glColor3f(1.0f, 0.0f, 0.0f); glBegin(GL_TRIANGLES); glVertex2f(0.3f, 0.5f); glVertex2f(0.5f, 0.7f); glVertex2f(0.7f, 0.5f); glEnd(); //square glBegin(GL_QUADS); glColor3f(0.0f, 0.5f, 1.0f); glVertex2f(0.7f, 0.2f); glVertex2f(0.3f, 0.2f); glVertex2f(0.3f, 0.5f); glVertex2f(0.7f, 0.5f); glEnd(); glBegin(GL_QUADS); glColor3f(0.0f, 0.5f, 0.5f); glVertex2f(0.35f, 0.35f); glVertex2f(0.45f, 0.35f); glVertex2f(0.45f, 0.45f); glVertex2f(0.35f, 0.45f); glEnd(); glBegin(GL_QUADS); glColor3f(0.0f, 0.5f, 0.5f); glVertex2f(0.55f, 0.35f); glVertex2f(0.65f, 0.35f); glVertex2f(0.65f, 0.45f); glVertex2f(0.55f, 0.45f); glEnd(); glBegin(GL_QUADS); glColor3f(0.2f, 0.2f, 0.0f); glVertex2f(0.45f, 0.2f); glVertex2f(0.55f, 0.2f); glVertex2f(0.55f, 0.33f); glVertex2f(0.45f, 0.33f); glEnd(); //circle glColor3f(1.0f, 0.5f, 0.0f); circle(0.1,0.1); glFlush(); //render } void spe_key(int key, int x, int y) { switch (key) { case GLUT_KEY_LEFT: tx -=5; glutPostRedisplay(); break; case GLUT_KEY_RIGHT: tx +=5; glutPostRedisplay(); break; case GLUT_KEY_DOWN: ty -=5; glutPostRedisplay(); break; case GLUT_KEY_UP: ty +=5; glutPostRedisplay(); break; default: break; } } int main() { glutInitWindowSize(600,600); glutInitWindowPosition(0,0); glutCreateWindow("CGLAB_TEST_1"); initGL(); glutDisplayFunc(display); glutMainLoop(); return 0; }