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);
}
 

 

  • 18cf2874-49da-3d4e-bf79-3c8958baea5e-thumb.png
  • 大小: 13.8 KB
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章