5

I have read around on this, including Nehe and here for solutions, but I cant find a specific answer.

I am trying to load a a photo, called stars.jpg. I want to make this my background of the scene, by mapping it using uv coordinates, doing it by

glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2f(0,0);

However I am just very confused about how to load the actual textures in, all the calls for

glActiveTexture();
glEnable(GL_TEXTURE_2d);
glBindTexture(GL_TEXTURE);

All they do is confuse me, what do all these mean/do, and in what order am I suppose to put these in, in order to get the stars.jpg to be my background?

4

2 回答 2

4

在 OpenGL 中加载纹理的第一工具是Simple OpenGL Image Loader (SOIL)库。你只需要传递文件名和一些标志,你就会得到你的纹理 ID。

此外,您现在正在学习非常旧且过时的 OpenGL 版本 - 您可能希望在 google 上获取更新的教程或随时浏览规范。

于 2010-11-27T11:31:11.563 回答
3

这是加载纹理的分步教程
http://www.nullterminator.net/gltexture.html

重要的是要记住 OpenGL 是一个状态机,所以你必须告诉它“我现在要谈谈纹理”这就是它的glActiveTexture();用武之地。

另请记住,您必须逐像素地将 .jpg(压缩)中的颜色加载到纹理数组中,因此您需要找到一个库来为您提供 .jpg 文件的位图值,或者您需要将其预先转换为 .ppm 或 .bmp,这将使读取值更容易。

于 2010-11-27T09:44:13.113 回答