`
dato0123
  • 浏览: 914874 次
文章分类
社区版块
存档分类
最新评论

OpenGL入门笔记(十七)

 
阅读更多
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->#include<windows.h>
#include
<GL/glut.h>
#include
<math.h>
#include
<stdlib.h>

voidInitGL(GLvoid)
{
glClearColor(
1.0,1.0,1.0,1.0);

}

voidtriangle(void)
{
glBegin(GL_TRIANGLES);
glColor3f(
1.0,1.0,0.0);
glVertex2f(
10.0,10.0);
glColor3f(
0.0,0.3,1.0);
glVertex2f(
20.0,30.0);
glColor3f(
1.0,0.0,0.0);
glVertex2f(
30.0,10.0);
glEnd();
}

voidDrawScene()
{
inti;
glClear(GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(
10.0,100.0,0.0);
triangle();
glPopMatrix();

for(i=0;i<5;i++)
{
glRasterPos2i(
20+i*30,10+i*5);
glCopyPixels(
50,200,500,500,GL_COLOR);
}
glPopMatrix();
glFlush();

}

voidReShape(intw,inth)
{
glViewport(
0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w<=h)
gluOrtho2D(
0.0,150,0.0,150.0*(GLfloat)h/(GLfloat)w);
else
gluOrtho2D(
0.0,150.0*(GLfloat)w/(GLfloat)h,0.0,150.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

}
intmain(intargc,char**argv)
{
glutInit(
&argc,argv);
glutInitDisplayMode(GLUT_SINGLE
|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(
500,400);
glutInitWindowPosition(
100,100);
glutCreateWindow(
"OpenGL");
InitGL();
glutReshapeFunc(ReShape);
glutDisplayFunc(DrawScene);
glutMainLoop();
return0;
}



200782802.jpg
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics