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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值