- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 C++,我尝试使用 DevIL 将纹理加载到 OpenGL 中。在四处寻找不同的代码段后,我完成了一些代码(如下所示),但它似乎无法完全工作。
加载纹理(Texture2D 类的一部分):
void Texture2D::LoadTexture(const char *file_name)
{
unsigned int image_ID;
ilInit();
iluInit();
ilutInit();
ilutRenderer(ILUT_OPENGL);
image_ID = ilutGLLoadImage((char*)file_name);
sheet.texture_ID = image_ID;
sheet.width = ilGetInteger(IL_IMAGE_WIDTH);
sheet.height = ilGetInteger(IL_IMAGE_HEIGHT);
}
这可以编译并且工作正常。我确实意识到我应该只执行一次 ilInit()、iluInit() 和 ilutInit(),但是如果我删除这些行,程序会在加载任何图像时立即中断(编译正常,但运行时出错)。
在 OpenGL 中显示纹理(同一类的一部分):
void Texture2D::Draw()
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glPushMatrix();
u = v = 0;
// this is the origin point (the position of the button)
VectorXYZ point_TL; // Top Left
VectorXYZ point_BL; // Bottom Left
VectorXYZ point_BR; // Bottom Right
VectorXYZ point_TR; // Top Right
/* For the sake of simplicity, I've removed the code calculating the 4 points of the Quad. Assume that they are found correctly. */
glColor3f(1,1,1);
// bind the appropriate texture frame
glBindTexture(GL_TEXTURE_2D, sheet.texture_ID);
// draw the image as a quad the size of the first loaded image
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glTexCoord2f (0, 0);
glVertex3f (point_TL.x, point_TL.y, point_TL.z); // Top Left
glTexCoord2f (0, 1);
glVertex3f (point_BL.x, point_BL.y, point_BL.z); // Bottom Left
glTexCoord2f (1, 1);
glVertex3f (point_BR.x, point_BR.y, point_BR.z); // Bottom Right
glTexCoord2f (1, 0);
glVertex3f (point_TR.x, point_TR.y, point_TR.z); // Top Right
glEnd();
glPopMatrix();
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
}
目前,四边形出现了,但它完全是白色的(给定的背景颜色)。我正在加载的图像存在并且加载正常(使用加载的尺寸值验证)。
还有几点需要注意:1)我正在使用深度缓冲区。我听说这不适用于 GL_BLEND?2) 我真的很想使用 ilutGLLoadImage 函数。3) 我很欣赏示例代码,因为我是 openGL 和 DevIL 的新手。
最佳答案
是的,你有问题。 ilutGLLoadImage() 可能存在问题。
尝试手动操作:
查看此链接以获得可行的解决方案
http://r3dux.org/tag/ilutglloadimage/
我知道,这个解决方案似乎“有点”复杂,但没有人知道你会花多少时间来解决这个隐藏在 DevIL 深处的错误。
另一种修复方法:检查 GL 纹理设置代码。过滤中的任何内容都可能是 GL_INVALID_OPERATION 的原因。
我们在为旧的 ATI 卡编程时多次遇到“白色纹理”问题。
哦!最大的猜测:非二次方纹理。您的纹理文件是 2^N x 2^N 还是其他?
要使用非矩形纹理,您只需使用 GL 扩展。
另一个:你是在同一个线程中还是在另一个线程中使用纹理?请记住,您应该在同一个线程中使用 glGenTextures() 和 glBindTexture()/glBegin/glEnd。
关于c++ - 使用 DevIL 在 C++ OpenGL 中加载纹理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10707230/
我正在使用 OpenGL,我可以正确加载 tga 文件,但由于某些原因,当我渲染 jpg 文件时,我看不到它们。 这就是图像应该看起来的样子—— 这就是它的样子..为什么它被拉伸(stretch)了?
好吧,事情是这样的。我有我需要的所有 IL 文件,即 DevIL.dll DevIL.lib ILU.dll ILU.lib ILUT.dll ILUT.lib config.h config.h.i
此代码示例正确吗?为什么有些_data具有相同的值?我如何获取 gif 图像中包含的每个动画帧的指针? _num = ilGetInteger(IL_NUM_IMAGES)+1; for (int i
链接这些库就像链接任何其他库一样。 但是当我运行我的项目时,我的问题出现了,我没有收到链接器错误,但我的错误是关于“DLL”的 我明白了 “该程序无法启动,因为您的计算机缺少 DevIL.dll。请尝
我想从原始纹理数据创建 devIL 图像,但我似乎找不到实现它的方法。正确的方法似乎是 ilLoadL with IL_RAW,但我无法让它工作。 here 中的文档说数据中应该有 13 字节的 he
我希望能够将 devIL 库用于我正在处理的项目,但由于某些原因我无法正确设置它。在我的项目中,我有: #include #include #include 如果我不调用任何 devIL 函数,
我正在使用 Visual Studio 2010,C++。 我想做的是从加载的图像中检索像素数据(特别是 RGB 颜色),然后在各种检查中使用它。目前,我想遍历所有数据并能够检测像素何时为某种颜色(特
我正在尝试检查图像中像素的 RGB 分量,但我不知道该怎么做。 import Data.Array.Repa import Data.Array.Repa.IO.DevIL import Data.W
在花费数小时寻找一种将图像添加到用 C++ 编写的 openGL 应用程序的简单方法之后,我惨遭失败。显然还有许多其他人也这样做了。 我是 OpenGL 的新手,我使用 DevIL 使用 OpenGL
我想将图像加载到我的应用程序中,但出现错误: http://img510.imageshack.us/img510/5814/blad07864.png 这是这个应用程序的代码: #include
我遇到一个问题,我想使用 DevIL 作为字节数组加载的 .png 图像没有 alpha channel 。 全黑图像也显示为 alpha channel 值为 0。 这是我的图片加载函数: DevI
只是阅读 DevIL 手册 here .也让我想起了glGenBuffers .为什么他们选择让每个库的用户生成名称(DevIL 手册第 6 页),而不是为您自己的图像/缓冲区等指定名称? 我想也许他
我只得到立方体贴图中的第一个面。我如何访问/加载其他的? 在 Ubuntu Natty 上使用 DevIL 1.7.8:我使用 ilLoad 或 ilLoadImage 加载一个包含 6 个纹理的 d
我正在尝试使用 Devil 将纹理加载到 OpenGL 中,但在调用此构造函数时出现段错误 Sprite::Sprite(const char *path){ ILuint tex = 0;
我正在尝试编译使用 OpenGL、SDL 和 IL aka DevIL aka OpenIL 库的示例源代码。 OpenGL 和 SDL 可用作 native 框架,但 DevIL 不是。所以这就是我
我正在使用 DevIL 编写 C++ OpenGL 项目,但在尝试找出如何加载图像以用作纹理时出现编译时错误。 到目前为止我有这个 //Declarations const char* filenam
首先,我正在使用 Fedora 并学习 OpenGL。我想稍微使用 DevIL,所以我从官方存储库安装了 DevIL 和 DevIL-ILUT 包。我有一个用于加载和呈现可用文件的测试代码,所以我决定
我的文件路径是这样定义的: const char* GROUND_TEXTURE_FILE = "objects/textures/grass.jpg"; 这是我用来加载图像的函数: bool loa
我目前正在将我的游戏从 Windows 移植到 Linux。 Debian(home) 和 Fedora(uni)。它构建良好,但在运行时预期 加载共享库时出错:libIL.so.1。 首先,.1 是
我正在编写一个使用 DevIL 的 Android 应用程序用于图像处理。我从 this project 得到了 DevIL 及其依赖库的端口.我编辑并提取了我需要的东西。它编译得很好,库也可以工作,
我是一名优秀的程序员,十分优秀!