Jump to content
  • Advertisement
Sign in to follow this  
Winegums

OpenGL OpenGL - Texture to array (and back again)

This topic is 3784 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm about to do some work with GPGPU and need to transfer my 2d array of information into a texture format. Whats the best way to do this? And how about going back again? I googled glWritePixel, but only a few results came up, so I'm not sure if this function actually exists. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Check out pixel buffer objects via the ARB_pixel_buffer_object extension. You can stream data from the pixel buffer to textures. Meaning that if you write to the pixel buffer, the texture is updated as well.

http://www.opengl.org/registry/specs/ARB/pixel_buffer_object.txt

Share this post


Link to post
Share on other sites
OK I've build this texture now, but if I try to render it it renders all in white. Is this possible without something being very wrong? I am making a texture of floats, so I'm not sure if I'm meant to do something special. I tried normalising all the values in the array before putting them into the texture but it didn't make a difference. Here's a code snippet:



unsigned int densityTexture = 0;

//Setup floating point number texture

// make active and bind
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, densityTexture);
// turn off filtering and wrap modes
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
// define texture with floating point format
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB,0,GL_RGBA32F_ARB,(N+2),(N+2),0,GL_RGBA,GL_FLOAT,0);

if (glGetError() != GL_NO_ERROR)
{
MessageBox(NULL, NULL, NULL, NULL);
}



static float dens[size];
static float tempArray[size];
float highestVal = dens[0];
for (int i=0 ; i<=N ; i++ )
{
for (int j=0 ; j<=N ; j++ )
{
if(dens[IX(i,j)] > highestVal)
{
highestVal = dens[IX(i,j)];
}
}

}
for (int i=0 ; i<=N ; i++ )
{
for (int j=0 ; j<=N ; j++ )
{
tempArray[IX(i,j)] = 0.0f;
if(dens[IX(i,j)] != 0.0f)
{
tempArray[IX(i,j)] = (dens[IX(i,j)])/highestVal;
}
else
{
tempArray[IX(i,j)] = 0.0f;
}
}
}

glBindTexture(GL_TEXTURE_RECTANGLE_ARB, densityTexture);
// turn off filtering and wrap modes
glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB,0,0,0,(N+2), (N+2),
GL_RGBA,GL_FLOAT,tempArray);






It's possible that I can't render with this directly, which is fine. But I don't want to make my job harder by pushing this onto the GPU, it not working, and me not realising it's because of the code here, and not the shader stuff.

EDIT: I read that Dominik Göddeke article, and it seemed good. Source code wouldn't run, however (failed on a glTexImage2D() call).

[Edited by - Winegums on February 11, 2008 9:00:12 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!