标签:
代码如下:
#include <windows.h> //#include <GLUT/glut.h> #include <GL/glut.h> #include <math.h> #include <iostream> using namespace std; #define GL_PI 3.1415f void RenderScene() { glClear(GL_COLOR_BUFFER_BIT); GLfloat y; GLint factor = 1; GLushort pattern = 0x5555; GLfloat sizes[2],curSize; glGetFloatv(GL_LINE_WIDTH_RANGE,sizes); glEnable(GL_LINE_STIPPLE); curSize = sizes[0]; for(y = -90.0f;y < 90.0f;y += 20.0f) { glLineStipple(factor,pattern); glLineWidth(curSize); glBegin(GL_LINES); glVertex2f(-80.0f,y); glVertex2f(80.0f,y); glEnd(); curSize += 1.0f; factor++; } glFlush(); } void ChangeSize(GLsizei w,GLsizei h) { if(h==0) h = 1; GLfloat aspectRatio = (GLfloat)w/(GLfloat)h; glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(w<=h) glOrtho(-100,100,-100/aspectRatio,100/aspectRatio,100.0,-100.0); else glOrtho(-100*aspectRatio,100*aspectRatio,-100,100,100.0,-100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void SetupRC() { glClearColor(0.0f,0.0f,0.0f,1.0f); glColor3f(1.0f,0.0f,0.0f); } int main(int argc, char *argv[]) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(800,600); glutCreateWindow("Simple"); glutDisplayFunc(RenderScene); glutReshapeFunc(ChangeSize); SetupRC(); glutMainLoop(); return 0; }
标签:
原文地址:http://www.cnblogs.com/lxk2010012997/p/4198276.html