opengl生成线框山地
2014-09-11 16:36
239 查看
#include "stdafx.h" #include <GL/glut.h> #include <time.h> #include <stdlib.h> #define MAP_W 32 #define MAP_SCALE 4.0f float g_terren[MAP_W*MAP_W][3]; int g_index[MAP_W*MAP_W*2]; float g_texcoord[MAP_W*MAP_W][2]; void init(void) { glClearColor(0.0,0.0,0.0,0.0); glShadeModel(GL_FLAT); } void display(void) { srand(time(NULL)); int index = 0; int Vertex; float h = 0.5; for(int z=0;z<MAP_W;z++) for(int x=0;x<MAP_W;x++){ Vertex = z*MAP_W+x; g_terren[Vertex][0]=float(x)*MAP_SCALE; g_terren[Vertex][1]=(float)(h+rand()%100/10*h); g_terren[Vertex][2]=float(z)*MAP_SCALE; /*g_texcoord[Vertex][0]=(float)x; g_texcoord[Vertex][1]=(float)z;*/ g_index[index++]=Vertex; g_index[index++]=Vertex+MAP_W; } glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3,GL_FLOAT,0,g_terren); glColor3f(1.0,1.0,1.0); for(int z=0;z<MAP_W-1;z++) { glDrawElements(GL_LINE_STRIP,MAP_W*2,GL_UNSIGNED_INT,&g_index[z*MAP_W*2]); } //glRotatef(-90.0,1.0,0.0,0.0); gluLookAt(70.0,60.0,110.0,70.0,0.0,0.0,0.0,1.0,0.0); } void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0, (GLfloat)w/(GLfloat)h, 1.0, 30000.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void keyboard (unsigned char key, int x, int y) { switch (key) { case 27: exit(0); break; default: break; } } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize (500, 500); glutInitWindowPosition (50, 50); glutCreateWindow (argv[0]); init (); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMainLoop(); return 0; }
相关文章推荐
- OpenGL 射线选择中射线的生成过程,代码与图示参考
- 德罗内三角形剖分生成以及opengl显示
- OpenGL glTexImage2D 纹理生成函数注意点
- Qt openGL 使用QImage 生成二维纹理
- Opengl如何从磁盘中加载图片生成纹理对象
- OpenGl(jogl)分形算法生成树
- 《OpenGL超级宝典》P38“2.6使用OpenGL和GLUT生成动画”勘误
- 用多边形近似球体表面(icosphere)的Mesh数据的生成并使用openGL绘制
- OpenGL三维球体体数据生成与绘制
- 初试PyOpenGL二 (Python+OpenGL)基本地形生成与高度检测
- OpenGL自动生成纹理步骤
- [OpenGL]纹理坐标的自动生成glTexGen
- OpenGL_生成位图
- NEHE的OPENGL中文教程 第34课 从高度图生成地形
- [OpenGL]课后案例02:生成Sierpinski镂垫的递归程序
- 【OpenGL】直线生成算法DDA+Bresenham
- OpenGL之自动纹理坐标生成
- 计算机图形学(二)输出图元_6_OpenGL曲线函数_3_椭圆生成算法
- OpenGL--自动生成纹理坐标
- OpenGL学习二十二:纹理坐标自动生成