I spent my weekend finding how to render to texture.
I encountered several problems, which are mostly due to my innocence.I found that I had never truly learnt about OpenGL before. Programming in OpenGL is really hard for me. There are so many features in the OpenGL. Often, to successfully render an image on the screen needs a lot of call for APIs. I was kind of lost and often forgot something, then I spent a lot of time finding those bugs. One problem was about the indices type. Meshes are deformed. Because the obj load source code use int type for indices. However, in OpenGL, there are only GL_UNSIGNED_BYTE and GL_UNSIGNED_SHORT.
Let me talk about what I have learnt this week. I learnt how to use the framebuffer of OpenGL. There are many attachments for a frame buffer, like color and depth. We could render both to buffers or texture objects. In my project, I use rendering to texture. In the glsl, we could directly write to the buffers, by specifying the out variables in shaders, also don't forget to give the out variables locations, so that the OpenGL know which variable write to which buffer.
Now I have a new problem. I don't know how to output two depth maps from just one shader. I input two transformation matrices and pass two position vecs into fragment shader .In the fragment shader, write them into output textures. Unfortunately, this method doesn't work..T T..
No comments:
Post a Comment