NeHe OpenGL Lesson42 - Multiple Viewports
2012-08-17 09:18
253 查看
![](http://images.cnblogs.com/cnblogs_com/open-coder/201208/201208180030511557.png)
This samples shows us how to create multiple views in one window. With OpenGL command glViewport, we could place our scene into any rectangle area on the window. Usually, we will set the view port to the size of the window or window client area. This will make one full window view display. With glviewport function, you could choose any rectangle area on a window to display your view. This command will take the left-bottom point as the original point, width goes along horizontally, and height goes along vertically.
Update OpenGL texture object dynamically
// tex_data contain RGB texture data glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, tex_data);
Create the maze texture data
Once you play a bit with the program, you will be curious about such maze texture created. Here is the main workflow:a) At first, we will choose a random position (2i, 2j) as the start point;
b) Check all position at (2i, 2j) are filled with color, if all of them are filled with color, then the process finished, otherwise continue;
c) Check current position (2i, 2j) is a validate position (this position will not beyond the rectangle area and could turn around: could turn up or down, left or right ). If this is validate position, continue; otherwise, use a while loop to randomly pick up an empty position (2i, 2j); continue;
d) randomly find a turn direction; filled with the new direction { 4 possibility, (2i+1, 2j), (2i-1, 2j), (2i, 2j+1), (2i, 2j-1) }if we could turn along this direction, and move the position to a new position (2n, 2m) { 4 possibility, (2i+2, 2j), (2i-2, 2j), (2i, 2j+2), (2i, 2j-2)};
e) fill color to (2n, 2m);
f) go to step b).
![]() | ![]() |
maze image | maze image without shading turn direction |
The full source code could be found here.
相关文章推荐
- NEHE的OpenGL-Lesson 03 Colors
- Nehe OpenGL lesson 8
- NeHe OpenGL Lesson45 - Vertex Buffer Objects
- NeHe OpenGL Lesson25 – Morphing & Loading Objects From A File
- NeHe OpenGL Lesson 10 – Loading And Moving Through A 3D World
- NEHE的OpenGL-Lesson 04 Rotations
- NeHe OpenGL Lesson40 - Rope Physics
- NeHe OpenGL Lesson46 - Fullscreen AntiAliasing
- NeHe OpenGL Lesson36 – Radial Blur(径向模糊)
- NeHe OpenGL Lesson24 – Tokens, Extensions, Scissor Testing And TGA Loading
- NeHe OpenGL Lesson09 - Moving Bitmaps in 3D Space
- NEHE的OpenGL-Lesson 05 Solid Objects
- OpenGL笔记:多视口(Multiple Viewports)
- NEHE的OpenGL-Lesson 06 Texture Mapping
- NeHe OpenGL Lesson34 – Beautiful Landscapes By Means Of Height Mapping
- NEHE的OpenGL-Lesson 07 Texture Filters, Lightning & Keyboard Control
- NeHe OpenGL Lesson43 - FreeType Fonts in OpenGL
- NeHe OpenGL Lesson33 – Loading Compressed And Uncompressed TGA’s
- Nehe OpenGL lesson 8
- NeHe OpenGL Lesson20 – Masking