Jump to content
  • Advertisement
Sign in to follow this  
LFDM

OpenGL Drawing image out of multi-channel interleaved data

This topic is 2854 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

Hello,

I'm hoping someone could give me a clue for implementing what I'm trying to do.

I'm reading a file containing a very large 3D array containing multichannel interleaved data (multiple GB).

Out of this big array I'm extracting only 3 arbitrary channels out of X for each frame in order to display an RGB representation.

So at the moment I have 3 arrays containing the values of each pixels in a raw for each color:

UINT16* pRedBand = new UINT16[width * height];
UINT16* pGreenBand = new UINT16[width * height];
UINT16* pBlueBand = new UINT16[width * height];

This is 2 byte unsingned data so I have been using GLushort type to try to create a bitmap buffer.

I tried to take the approach of creating a texture but every time I call glTexImage2D I get a GL_INVALID_VALUE error code most certainly due to the fact that the texture dimensions are not power of 2 for with and height.

But if I create a texture of out of power of 2 dimensions then I'll have an oversize texture and will have a wrong aspect ratio when trying to draw the texture am I right?

Have I taken a wrong approach?

How can I create an image of arbitrary size and draw it using OpenGL.

Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
With what arguments are you calling glTexImage2d? Are you absolutely certain that that call is giving you the error? (put glGetError before/after the call).

Quote:


But if I create a texture of out of power of 2 dimensions then I'll have an oversize texture and will have a wrong aspect ratio when trying to draw the texture am I right?



If you do have to use PoT textures (which is kind of surprising, that hasn't been a requirement on modern hardware for a while), then there's no requirement that you draw the whole texture. When you draw you get to choose what parts of the texture you want to draw from, so the aspect ratio when you draw is entirely up to you and shouldn't be a problem. The only potential downside of PoT textures vs non-PoT is a little bit of wasted vidmem. The end result should look exactly the same.

Share this post


Link to post
Share on other sites
Hi karwosts!

Thanks for answering! The code is not rocket science and I can share it with you. The building of the image buffer is unfinished.


UINT nSamples = GetSamples();
UINT nLines = GetLines();
UINT16* pRedBand = GetRedBandBuffer();
UINT16* pGreenBand = GetGreenBandBuffer();
UINT16* pBlueBand = GetBlueBandBuffer();
GLushort* pImageBuf = new GLushort[nSamples * nLines * 3];

ZeroMemory(pImageBuf, nSamples * nLines * 3 * sizeof(GLushort));

UINT nOffset = 0;
UINT nPointer = 0;

for(UINT nHeight = 0; nHeight < nLines; nHeight++)
{
for(UINT nWidth = 0; nWidth < nSamples; nWidth++)
{
nPointer = nHeight * nWidth;
nOffset = nPointer * 3;

// Red
pImageBuf[nOffset] = pRedBand[nPointer];

// Green
pImageBuf[nOffset + 1] = pGreenBand[nPointer];

// Blue
pImageBuf[nOffset + 2] = pBlueBand[nPointer];
}
}

glEnable(GL_TEXTURE_2D);
glGenTextures(1, &m_nTexture1);
glBindTexture(GL_TEXTURE_2D, m_nTexture1);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, nSamples, nLines, 0, GL_RGB, GL_UNSIGNED_SHORT, pImageBuf);

Maybe you are better able to tell me what I am doing wrong. I went through the code and tested line by line, the gl error comes only after calling glTexImage2D.

Any thoughts?

Thanks!

Share this post


Link to post
Share on other sites
Firstly there seems to be a mistake in your loop. Shouldn't nPointer be
nPointer = nHeight * nSamples + nWidth

EDIT: Also I think that OpenGL pads rows so that they are even. So if nSamples * 3 is an odd number, glTexImage2D might be expecting rows of nSamples * 3 + 1

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!