#include <windows.h> // Must have for Windows platform builds
#include <gl/gl.h> // Microsoft OpenGL headers (version 1.1 by themselves)
#include <gl/glu.h> // OpenGL Utilities
#include <gl/glut.h>" // Glut (Free-Glut on Windows)
///////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
{
// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT); // 清除屏幕及深度缓存
glLoadIdentity(); // 重置当前的模型观察矩阵
glTranslatef(-1.5f,0.0f,-6.0f); // 左移 1.5 单位,并移入屏幕 6.0
glBegin(GL_TRIANGLES); // 绘制三角形
glVertex3f( 0.0f, 1.0f, 0.0f); // 上顶点
glVertex3f(-1.0f,-1.0f, 0.0f); // 左下
glVertex3f( 1.0f,-1.0f, 0.0f); // 右下
glEnd();
glTranslatef(3.0f,0.0f,0.0f); // 右移3单位
glBegin(GL_QUADS); // 绘制正方形
glVertex3f(-1.0f, 1.0f, 0.0f); // 左上
glVertex3f( 1.0f, 1.0f, 0.0f); // 右上
glVertex3f( 1.0f,-1.0f, 0.0f); // 左下
glVertex3f(-1.0f,-1.0f, 0.0f); // 右下
glEnd(); // 正方形绘制结束
// Flush drawing commands
glFlush();
}
///////////////////////////////////////////////////////////
// Called by GLUT library when the window has chanaged size
void ChangeSize(int width, int height)
{
if (height==0) // Prevent A Divide By Zero By
{
height=1; // Making Height Equal One
}
glViewport(0,0,width,height); // Reset The Current Viewport
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
}
///////////////////////////////////////////////////////////
// Setup the rendering state
void SetupRC(void)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
}
///////////////////////////////////////////////////////////
// Main program entry point
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutCreateWindow("Simple");
glutDisplayFunc(RenderScene);
glutReshapeFunc(ChangeSize);
SetupRC();
glutMainLoop();
return 0;
}

JonSco
- 粉丝: 111
最新资源
- web项目测试实战性能测试结果分析样章报告.doc
- 分层式教学模式在高职计算机教学中的应用.docx
- WindowsCE嵌入式应用.ppt
- C语言单项选择题.doc
- 基于架构式的电力远程监控系统模型建立和软件设计的开题报告.docx
- 《网络安全和管理》试题及答案解析(一)(已做).doc
- 2023年全国大学生物联网设计竞赛模板.docx
- MSP单片机硬件设计及接口技术教学教材.ppt
- MATLAB程序的设计教程第二版资料课后答案.doc
- 【财务会计论文】信息化内部审计论文(共2917字).doc
- 2015年网络编辑考试模拟试题及答案.pdf
- plc-电动机“长动+点动”控制.ppt
- 精选网站转让合同三篇.docx
- 基于互联网金融视角的商业银行发展策略探析.docx
- 浅析Access在有线电视网络工程信息化管理中的应用.docx
- 电子商务和支付试题.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


