简体   繁体   English

纹理映射C ++ OpenGL

[英]Texture Mapping C++ OpenGL

I have read around on this, including Nehe and here for solutions, but I cant find a specific answer. 我已经读过这个,包括Nehe和这里的解决方案,但我找不到具体的答案。

I am trying to load aa photo, called stars.jpg. 我正在尝试加载一张名为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? 他们所做的只是让我感到困惑,所有这些是什么意思/做什么,以及我想以什么顺序把它们放进去,以便让stars.jpg成为我的背景?

Your number-one tool for loading textures in OpenGL is the Simple OpenGL Image Loader (SOIL) library. 您在OpenGL中加载纹理的第一个工具是Simple OpenGL Image Loader(SOIL)库。 You just need to pass the filename and some flags and you'll get your texture ID. 你只需要传递文件名和一些标志,你就会得到你的纹理ID。

Also, you're learning very old and outdated version of OpenGL now - you might want to have a google for newer tutorials or browse the specs whenever you feel ready. 此外,您现在正在学习非常陈旧且过时的OpenGL版本 - 您可能希望获得谷歌更新的教程或在您准备好时浏览规范

Here's a step by step tutorial on loading textures 这是一个关于加载纹理的分步教程
http://www.nullterminator.net/gltexture.html http://www.nullterminator.net/gltexture.html

Its important to remember that OpenGL is a state machine, so you have to tell it "I'm going to talk about textures now" that's where the glActiveTexture(); 重要的是要记住OpenGL是一个状态机,所以你必须告诉它“我现在要讨论纹理”这就是glActiveTexture(); comes in. 进来。

Also keep in mind that you will have to load in pixel by pixel the colors from your .jpg (compressed) to your texture array, so either you will need to find a library that will give you bitmap values of your .jpg file or you will need to pre-convert it into a .ppm or a .bmp which will make reading in the values easier. 另外请记住,您必须逐个像素地加载.jpg(压缩)到纹理数组的颜色,因此您需要找到一个库,它将为您提供.jpg文件的位图值或者您需要将其预先转换为.ppm或.bmp,这将使得读取值更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM