NeHe OpenGL Lesson 10 – Loading And Moving Through A 3D World

screen_shot3-300x237 This sample shows us a small proto-type how to write a game with OpenGL. This is the first lesson that abandon using hard code game world. It seems like a engine, a small one. What is an engine? An engine just define a group of data structures and data manager.
In this lesson, the game world saved as a text file, also human readable. The program will load and parse this text format game world. Parsing string and text, this is a bit time wasting. A better method is to binarize those data as disc file. At the game running time, load those data with a chunk of memory, then you could use it directly without eat one char by one char to get what are reading. Well, this will get into the engine asset pipeline and game resource management, data compress, data de-compress and so on. That is a big topic beyond this lesson.

 

OpenGL Texture Object

Texture object: In OpenGL, we could set the texture filter mode, address mode for each texture object. Just as the following code, those settings go along with OpenGL texture objects.

// Create Nearest Filtered Texture
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);

When you want to use this texture object, what you need to do is like this:

glBindTexture(GL_TEXTURE_2D, texture[filter]);

This is very different from the D3D texture filter mode set up. In D3D, you need to call SetSamplerState() to archieve to do that. What you should do is set the current d3d texture to this sample slot, then you set the filter mode, address for the current sample slot.

 

OpenGL Texture Sample Slots

Here comes another questions, how about texture sample slots in OpenGL? By default, we use the texture sample slot 0 for using, if we want to use multiple texure slots at the same time, you should write some code like this:

glActiveTexture(GL_TEXTURE0);
// bind the first texture handle to this slot
glBindTexture(GL_TEXTURE_2D, textureAId);

// activate the second texture slot
glActiveTexture(GL_TEXTURE0 + textureNumber);
// bind the first texture handle to this slot
glBindTexture(GL_TEXTURE_2D, textureBId);

You active the current texture sample slot, then set it. When you do not need this texture slot, you could use glBindTexture(.., NULL) to unbind the current texture unit.

Maximum Texture Sample Number

There is a maximum number of texture units that can be simultaneously supported on graphics hardware. Usually this is either 8 and 16 textures that can be used in one shader. We can find out exactly how many with in OpenGL:

int maxTextures = glGet(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS);

For more details about how to implement this demo, you could refer to NeHe OpenGL lesson 10.

 

The full source code could be found here.

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

NeHe OpenGL教程(中英文版附带VC++源码)中英文系列 Lesson 01-lesson 02 创建一个OpenGL窗口: 如何创建三角形和四边形 http://ieee.org.cn/dispbbs.asp?boardID=61&ID=53679 Lesson 03-lesson 04 添加颜色 旋转 http://ieee.org.cn/dispbbs.asp?boardID=61&ID=53682 Lesson 05-lesson 06 3D空间 纹理映射 http://ieee.org.cn/dispbbs.asp?boardID=61&ID=53706 Lesson 07-lesson 08 光照和键盘控制 混合 http://ieee.org.cn/dispbbs.asp?boardID=61&ID=53709 Lesson 09-lesson 10 3D空间中移动图像 加载3D世界,并在其中漫游 http://ieee.org.cn/dispbbs.asp?boardID=61&ID=53822 Lesson 11-lesson 12 飘动的旗帜 显示列表 http://ieee.org.cn/dispbbs.asp?boardID=61&ID=53823 Lesson 13-lesson 14 图像字体 图形字体 http://ieee.org.cn/dispbbs.asp?boardID=61&ID=53880 Lesson 15-lesson 16 图形字体的纹理映射 雾 http://ieee.org.cn/dispbbs.asp?boardID=61&ID=53881 Lesson 17-lesson 18 2D 图像文字 二次几何体 http://ieee.org.cn/dispbbs.asp?boardID=61&ID=54042 Lesson 19-lesson 20 粒子系统 蒙板 http://ieee.org.cn/dispbbs.asp?boardID=61&ID=54072 Lesson 21-lesson 22 线,反走样,计时,正投影和简单的声音 凹凸映射,多重纹理扩展 http://ieee.org.cn/dispbbs.asp?boardID=61&ID=54074 Lesson 23-lesson 24 球面映射 扩展,剪裁和TGA图像文件的加载 http://ieee.org.cn/dispbbs.asp?boardID=61&ID=54176 Lesson 25-lesson 26 变形和从文件中加载3D物体 剪裁平面,蒙板缓存和反射 http://ieee.org.cn/dispbbs.asp?boardID=61&ID=54177 Lesson 27-lesson 28 影子 贝塞尔曲面 http://ieee.org.cn/dispbbs.asp?boardID=61&ID=54180 Lesson 29-lesson 30 Blitter 函数 碰撞检测 http://ieee.org.cn/dispbbs.asp?boardID=61&ID=54186 Lesson 31-lesson 32 模型加载 拾取, Alpha混合, Alpha测试, 排序 http://ieee.org.cn/dispbbs.asp?boardID=61&ID=54209 Lesson 33-lesson 34 加载压缩和未压缩的TGA文件 从高度图生成地形 http://ieee.org.cn/dispbbs.asp?boardID=61&ID=54271 Lesson 35-lesson 36 在OpenGL中播放AVI 放射模糊和渲染到纹理 http://ieee.org.cn/dispbbs.asp?boardID=61&ID=54289 Lesson 37-lesson 38 卡通映射 从资源文件中载入图像 http://ieee.org.cn/dispbbs.asp?boardID=61&ID=54290 Lesson 39-lesson 40 物理模拟简介 绳子的模拟 http://ieee.org.cn/dispbbs.asp?boardID=61&ID=54706 Lesson 41-lesson 42 体积雾气 多重视口 http://ieee.org.cn/dispbbs.asp?boardID=61&ID=54707 Lesson 43-lesson 44 在OpenGL中使用FreeType库 3D 光晕 http://ieee.org.cn/dispbbs.asp?boardID=61&ID=54710 Lesson 45-lesson 46 顶点缓存 全屏反走样 http://ieee.org.cn/dispbbs.asp?boardID=61&ID=54729 Lesson 47-lesson 48 CG 顶点脚本 轨迹球实现的鼠标旋转 http://ieee.org.cn/dispbbs.asp?boardID=61&ID=54730
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值