OpenGL 纹理加载问题 [英] OpenGL texture loading issue

查看:43
本文介绍了OpenGL 纹理加载问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常模糊的问题,因此请随时澄清有关此项目的任何信息.

This is a very vague problem, so please feel free to clarify anything about this project.

我正在开发一个非常大的应用程序,最近出现了一个关于纹理的非常令人困惑的错误.我们正在加载的一些纹理正在加载 - 我已经逐步完成了代码,它会运行 - 但是这些纹理的所有 OpenGL 渲染都是一个奇怪的粉红色/白色条纹纹理.

I'm working on a very large application, and recently a very perplexing bug has cropped up regarding the texturing. Some of the textures that we are loading are being loaded - I've stepped through the code, and it runs - but all OpenGL renders for those textures is a weird Pink/White striped texture.

你有什么建议甚至开始调试这种情况?

What would you suggest to even begin debugging this situation?

  • 该项目是多线程的,但互斥锁可确保所有 OpenGL 调用不会被其他任何东西中断.
  • 有些纹理正在加载,有些则没有.它们都以完全相同的方式加载.
  • 我确保所有纹理都存在
  • 粉红色/白色"纹理肯定会加载到内存中 - 在我将任何其他纹理加载到 OpenGL 后不久它们就会变得可见.

我很困惑,不知道还有什么问题.是否有可以在 glTexImage 之后调用的 OpenGL 命令来强制纹理变得可用?

I'm perplexed, and have no idea what else can be wrong. Is there an OpenGL command that can be called after glTexImage that would force the texture to become useable?

这与命令失败无关,主要是时间问题.粉红色/白色纹理会显示一段时间,直到加载更多纹理.这几乎就像纹理在排队,而队列只是在某个时间暂停.

It's not about the commands failing, it's mainly a timing issue. The pink/white textures show up for a while, until more textures are loaded. It's almost as if the textures are queued up, and the queue just pauses at some time.

下一个我让 glIntercept 日志正常工作,这就是它输出的内容(在整个程序崩溃之前)

Next I got the glIntercept log working correctly, and this is what it outputted (before the entire program crashed)

http://freetexthost.com/1kdkksabdg

下一个我知道纹理是在 OpenGL 内存中加载的,但由于某种原因,它们没有在程序本身中进行渲染.

Next I know for a fact the textures are loaded in OpenGL memory, but for some reason they're not rendering in the program themselves.

推荐答案

检查您的纹理坐标.如果它们设置错误,您只能看到一两个纹素映射到整个图元.请记住,OpenGL 是一个状态机.检查您是否在错误的时间更改了纹理坐标状态.您可能会在稍后的代码中设置纹理坐标,然后当您重新绘制这些元素时,状态对于将纹理映射到代码是可以接受的.

Check your texture coordinates. If they are set wrong, you can see just one or two texels mapped to entire primitives. Remember, OpenGL is a state machine. Check if you're changing the texture coordinate state at the wrong time. You may be setting the texture coordinates at a later point in your code, then when you get back to redrawing these elements the state is acceptable for mapping your texture to the code.

如果仅仅是时序问题,未及时执行纹理加载 OpenGL 调用,并且您的线程代码正确,请尝试在加载纹理后添加对 glFlush() 的调用.glFlush() 使所有挂起的 OpenGL 命令执行.

If it is merely a timing issue where the texture loading OpenGL calls aren't executed in time, and your threading code is correct, try adding a call to glFlush() after loading the textures. glFlush() causes all pending OpenGL commands to execute.

这篇关于OpenGL 纹理加载问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆