Skip to main content
gamedev.net
🔒 Locked

Rendering with DIBs

Started by Frawley 3 replies 1.1k views
Original Post
Frawley
Frawley
Hello. I am trying to use a DIBSection as a render target so I can draw on it with OGL, and then I want to use that as a texture. I have successfully rendered to the DIBSection, but when I try to use it as a texture, it just appears white. In simplified form, here is what I am doing:

wglMakeCurrent(dc, rc); // DIBSection's dc and rc
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0, 0, 1, 1); // Just use a blue texture for now..
glBindTexture(GL_TEXTURE_2D, m_index);
glTexImage2D(GL_TEXTURE_2D, 0, 4, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_data); // m_data is the buffer created by CreateDIBSection
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

wglMakeCurrent(wdc, wrc); // Window's dc and rc
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1, 0, 0, 1);
glBindTexture(GL_TEXTURE_2D, index); // index is the texture name of the DIBSection, obtained from glGenTextures()
{draw a texture mapped cube here}


After calling this code, I can see an all white cube with no texture. Maybe I am doing something wrong to convert the DIB into a gl-usable texture. Any help will be greatly appreciated.
AndyEsser
AndyEsser
If you are using multiple rendering contexts then need to call wglShareLists() when you set them up so that textures/etc are shared across the different contexts.

I believe this is the reason you are seeing a white texture.

HTH
Frawley
Frawley
I tried your suggestion and the texture is still white :( I just want to make sure I'm doing this right:

Setting up the window's render context:Set up the PIXELFORMATDESCIPTORCreate the window render context using the window's DCOGL should be able to render to the backbufferSetting up the DIBSection render context and texture:Create a DIBSection and select a bitmap into a DC.Create an OGL render context using wglCreateContext()Also set the DIB as a texture by using glGenTextures and glTexImage2D with the buffer set to the DIB's dataNow OGL should be able to render to the DIB using standard calls


Now I clear the DIB texture to blue and try to render it on a textured cube on the window render context. This is where I think the problem occurs.
Yann L
Yann L
Don't forget that you need to render to your DIB before copying it into the texture ! You seem to be creating a texture from an (empty) DIB, and then render into the DIB. Which will obviously not update the texture.

That said, what exactly are you trying to achieve ? Your approach over a DIB is very uncommon. I'm not sure how well it is supported across different hardware and drivers. It working could very well only be a side effect. Expect a lot of problems with different GPU and driver combinations. Oh, and obviously this method is incredibly inefficient.

Have you considered actually hardware accelerated render texture approaches, such as FBOs ?
Frawley
Frawley
Well I have no problem using different render to texture methods. I'll look into FBO's.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.