NeHe OpenGL Lesson42 - Multiple Viewports

Lesson42_screenshot

    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:

  1. a) At first, we will choose a random position (2i, 2j) as the start point;
  2. 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).
    amaze_shotamaze02_shot
    maze imagemaze image without shading turn direction

 

The full source code could be found here.

转载于:https://www.cnblogs.com/open-coder/archive/2012/08/17/2643452.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值