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

本文探讨了使用OpenGL进行游戏开发的基本概念,包括如何定义游戏世界数据结构、纹理过滤模式和地址模式设置,以及如何管理和使用多个纹理样本槽。文章还讨论了数据管理的重要性,如文本格式游戏世界的解析和数据的二进制存储,以及OpenGL纹理对象和样本槽的具体操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值