OpenGL | Render Vertex at UV coordinate

坚强是说给别人听的谎言 提交于 2019-12-25 09:27:46

问题


I'm using OpenGL and I need to render the vertecies of a 3D model to a FBO at the UV coordinate of the vertex. To do that, I first have to convert the UV coordinate space to the screen space.

I came to the conclusion that:

uv.x * 2 - 1
uv.y * 2 - 1

…should do the trick.

I used that in my vertex shader to place the vertex at those new positions. The result looks like this:

…while it should should look like this:

It seems like it's scaled up. I dont know where the problem is.


回答1:


Are you certain that your screen space spans -1 to 1 rather than -0.5 to 0.5?

Try just subtracting 0.5 from both x and y.




回答2:


Fixed the problem, I did not call gl viewport which was the reason the coordinate system wasn't applied to the fbo texture size



来源:https://stackoverflow.com/questions/41938722/opengl-render-vertex-at-uv-coordinate

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!