项目实战学习笔记| OpenGl C++语言开发小行星系统 | 实验楼项目

源代码下载:https://download.csdn.net/download/u012737193/10307716


点击上下左右调整观看视角

源代码下载:https://download.csdn.net/download/u012737193/10307716

Main.cpp文件:

#include <GL/glut.h>//只要包含了这个头文件,

可以通过以下三个文件,设置点击键盘事件,屏幕刷新事件和静止的时候执行的函数

glutDisplayFunc(onDisplay);

glutIdleFunc(onUpdate);

glutKeyboardFunc(onKeyboard);

 

#include <GL/glut.h>

#include "solarsystem.hpp"

 

#define WINDOW_X_POS 50

#define WINDOW_Y_POS 50

#define WIDTH 700

#define HEIGHT 700

 

SolarSystem solarsystem;

 

void onDisplay(void) {

    solarsystem.onDisplay();

}

void onUpdate(void) {

    solarsystem.onUpdate();

}

void onKeyboard(unsignedchar key,int x, int y) {

    solarsystem.onKeyboard(key, x, y);

}

int main(int argc,char * argv[]){

glutInit(&argc,argv);

glutInitDisplayMode(GLUT_RGBA| GLUT_DOUBLE);

glutInitWindowPosition(WINDOW_X_POS,WINDOW_Y_POS);

glutCreateWindow("SolarSytem at Shityanlou");

glutDisplayFunc(onDisplay);

glutIdleFunc(onUpdate);

glutKeyboardFunc(onKeyboard);

glutMainLoop();

return 0;

}

来源: 实验楼

链接: https://www.shiyanlou.com/courses/558

 

 

Stars.hpp文件:

#ifndef star_hpp//这个头文件的功能就是当star_hpp存在的时候不执行#ifndef#endif之间的内容

#define star_hpp

#include <GL/glut.h>

class Star {

public :

GLfloat radius;

GLfloat speed,selfSpeed;

GLfloat distance;

GLfloat rgbaColor[4];

Star * parentStar;

Star(GLfloat radius,GLfloatdistance,GLfloatspeed,GLfloatselfSpeed,Star*parent);

void drawStar();

virtual void draw() {drawStar();}

virtual void update(longtimeSpan);

protected:

GLfloat alphaSelf,alpha;

};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值