C++ opengl 绘制地面
生活随笔
收集整理的這篇文章主要介紹了
C++ opengl 绘制地面
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
程序運行如下:
?
注意:主要是法線
?
源碼如下:
ground.h
#pragma once#include "ggl.h"class Ground { public:void Draw(); };ground.cpp
#include "ground.h"void Ground::Draw() {glEnable(GL_DEPTH_TEST);glDisable(GL_TEXTURE_2D);glBegin(GL_QUADS);glNormal3f(0.0f, 1.0f, 0.0f);for (int z = 0; z < 20; z++) {float zStart = 100.0f - z*10.0f;for (int x = 0; x < 20; x++) {float xStart = x*10.0f - 100.0f;if ((z % 2) ^ (x % 2)) {glColor4ub(41, 41, 41, 255);}else {glColor4ub(200, 200, 200, 255);}glVertex3f(xStart, -1.0f, zStart);glVertex3f(xStart + 10.0f, -1.0f, zStart);glVertex3f(xStart + 10.0f, -1.0f, zStart - 10.0f);glVertex3f(xStart, -1.0f, zStart - 10.0f);}}glEnd(); }?
總結
以上是生活随笔為你收集整理的C++ opengl 绘制地面的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Qt工作笔记-Qt奇淫技巧把ToolBa
- 下一篇: Linux学习笔记-动态库的使用