首页 > 其他 > 详细

opengl画星星

时间:2017-04-04 11:52:04      阅读:313      评论:0      收藏:0      [点我收藏+]
#include <windows.h>

#include <gl/gl.h>
#include <gl/glaux.h>

#include <math.h>
#define pi 3.1415926

#pragma comment (lib, "opengl32.lib")  
#pragma comment (lib, "glu32.lib")  
#pragma comment (lib, "glaux.lib")  

#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" ) 

void init()
{
      glClearColor(0.0,0.0,0.0,1.0);
}


float r=0,g=0,b=0;
float x=0.0f,y=0.0f,r0=0.0f,r1=0.0f,a=0.0f;

void CALLBACK draw()
{        
	if(rand()%5==0)
	{glClear(GL_COLOR_BUFFER_BIT);
     	Sleep(300);
	}

        glColor3f(r,g,b); 
        glBegin(GL_LINE_LOOP);
		double angl;
		double k,p;
	
		for(int i=0;i<5;i++)
		{
			angl = a/180*pi;
			k=(double)x+r1*cos(angl);
	     	p=(double)y+r1*sin(angl);
            glVertex2f(k,p);
            a=a+36;
            angl = a/180*pi;
	    	k=(double)x+r0*cos(angl);
		    p=(double)y+r0*sin(angl);
            glVertex2f(k,p);
		    a=a+36;
		}
		

     glEnd();
     glFinish();
}

void CALLBACK change()
{
	int i; 
   

	i=rand()%100+1;
    r0 = (float)i+4;
	r1 = r0/2.5;
	
	r = rand()%200 / 200.0f; 
	g = rand()%200/ 200.0f;
	b = rand()%200/ 200.0f;

	a=float(rand()%360);
      
	x=float(rand()%500);
	y=float(rand()%500);
		
	draw();     
}
void main()
{
    auxInitDisplayMode(AUX_SINGLE|AUX_RGBA);
    auxInitPosition(100,100,500,500);
    auxInitWindow("CGOpenGL");

    init();
	auxIdleFunc(change);
    auxMainLoop(draw);	
}

技术分享

opengl画星星

原文:http://www.cnblogs.com/jiangnanyanyuchen/p/6664448.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!