博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Lesson 9 Nehe
阅读量:6921 次
发布时间:2019-06-27

本文共 2737 字,大约阅读时间需要 9 分钟。

#include 
#include
HGLRC hRC = NULL;HDC hDC = NULL;HWND hWnd = NULL;HINSTANCE hInstance = NULL;BOOL keys[256];BOOL active = TRUE;BOOL fullscreen = FALSE;BOOL twinkle = FALSE; // 星星是否闪烁BOOL tp = FALSE; // t 键是否按下const int num = 50; // 星星的数目// 星星的结构typedef struct{ int r, g, b; GLfloat dist; GLfloat angle;}stars;// 定义50个星星stars star[num]; GLfloat zoom = -15.0f; // 星星离观察者的距离GLfloat title = 90.0f; // 星星的倾角GLfloat spin; // 闪烁星星的自转GLuint loop; // 循环变量GLuint texture[1]; // 存一个纹理LRESULT CALLBACK WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);AUX_RGBImageRec* LoadBMP(char* FileName){ FILE *File = NULL; if (!FileName){ MessageBox(NULL, "文件未存在", "错误", MB_OK|MB_ICONEXCLAMATION); return NULL; } File = fopen(FileName, "r"); if (!File){ MessageBox(NULL, "文件未能正常打开", "错误", MB_OK|MB_ICONEXCLAMATION); return NULL; } fclose(File); return auxDIBImageLoad(FileName);}BOOL LoadGLTexture(char* Filename, GLuint* texture){ BOOL Status = FALSE; AUX_RGBImageRec *TextureImage[1]; memset(TextureImage, 0, sizeof(void*)*1); if (TextureImage[0] = LoadBMP(Filename)){ Status = TRUE; // 创建一个纹理 glGenTextures(1, texture); glBindTexture(GL_TEXTURE_2D, *texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); } if (TextureImage[0]){ if (TextureImage[0]->data) free(TextureImage[0]->data); free(TextureImage[0]); } return Status;}GLvoid ReSizeGLScene(GLsizei width, GLsizei height){ // 如果高为0 , 则设置其为1 if (height == 0) height = 1; // 设置可以看到的视角 glViewport(0,0,width, height); // 设置投影矩阵 glMatrixMode(GL_PROJECTION); glLoadIdentity(); // 设置平截头体 gluPerspective(45.0f, (GLdouble)width/(GLdouble)height, 0.1f, 100.0f); // 设置模型矩阵 glMatrixMode(GL_MODELVIEW); glLoadIdentity();}GLvoid InitGL(){ if (!LoadGLTexture("Data/Star.bmp", &texture[0])){ MessageBox(NULL, "载入纹理失败", "错误", MB_OK|MB_ICONEXCLAMATION); exit(1); } glEnable(GL_TEXTURE_2D); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glShadeModel(GL_SMOOTH); //glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // 设置颜色混合 glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_BLEND); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // 星星属性设置 for (loop=1; loop

这里写图片描述

转载于:https://www.cnblogs.com/laohaozi/p/8266591.html

你可能感兴趣的文章
九九乘法表
查看>>
Mac系统常用快捷键及技巧
查看>>
linux基础篇-17,find命令详解
查看>>
FastDFS分布式文件存储搭建
查看>>
autolay适配ios7以及iPhone4
查看>>
CentOS 7常用软件安装
查看>>
Linux(4)-03
查看>>
Memory Overcommitment in the ESX Server
查看>>
我的友情链接
查看>>
ads模式Samba服务器配置示例
查看>>
Android怎么打开和调用系统自带的程序示例(06)
查看>>
Exchange2013 SP1的详细安装及配置
查看>>
IOS中定时器NSTimer的开启与关闭以及怎样计算label的大小的方法
查看>>
将博客搬至CSDN
查看>>
浅 谈 Servlet
查看>>
怎么把PDF文档中的重要信息改成红色字体
查看>>
清理神器 CleanMyMacX 提前开战“618”
查看>>
一加生不逢时面临两难选择 重走魅族老路or卷入小米漩涡
查看>>
收购艺龙,携程“居心叵测”,用垄断倒逼去哪儿
查看>>
我的友情链接
查看>>