openGL 小例子


openGL 小例子

 

#include <GL/gl.h>
#include <GL/glaux.h>
#define PI 3.1415926535897 

int main(int argc, char** argv){
    
    auxInitDisplayMode (AUX_SINGLE | AUX_RGBA);
    auxInitPosition (0, 0, 300, 300);
    auxInitWindow(argv[0]);
    
    glClearColor(1.0,0.0,1.0,0.5);//magenta
    // glClearDepth(0.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    // specify the point size in pixel.
    // non-antialiasing defaultly.
    glPointSize(5.0);
    
    //paint a ploygon on the screen.
    glBegin(GL_POINTS);
    glColor3f(0.0,0.0,0.0);
    glVertex2f(0.0,0.0);//v0
    glVertex2f(0.1,0.1);//v1
    glVertex2f(0.2,0.1);//v2
    glVertex2f(0.4,0.0);//v3
    glVertex2f(0.5,-0.1);//v4       
    glEnd();
    
    // draw a stipple lines.
    glEnable(GL_LINE_STIPPLE);
    glLineStipple(1,0xAAAA);
    glBegin(GL_LINES);
       
    glVertex2f(0.0,0.0);
    glVertex2f(0.0,0.5);
    //glDisable(GL_LINE_STIPPLE);
    glEnd();
    glDisable(GL_LINE_STIPPLE);
    glBegin(GL_LINE_LOOP);
    //draw a circle with specific points.
    int circle_points = 100;
    float angle = 0;
    int i = 0;
    
    for(i = 0;i<circle_points;i++) {
        // draw with yellow and black in turn.
        if(i%2==0){
          glColor3f(1.0,1.0,0.0);       
        }else{
          glColor3f(0.0,0.0,0.0);
        }
        angle = 2*i*PI/circle_points;
        //the cos and sin will occupy hole screen.
        glVertex2f(0.5*cos(angle),0.5*sin(angle));    
    }
    glEnd();
    
    //must add this to flush the buffer, so we can see the new picture.
    glFlush();
    Sleep(5000);
}
 

 

你可能感兴趣的:(OpenGL)