View Full Version : Pulling color data from texture coordinates
08-08-2008, 12:11 AM
is there anyway to gather the color data from the UVs in C++, without using GLSL?? Thanks!!!
08-08-2008, 03:57 AM
Not sure if I understand what you want to do.
08-08-2008, 09:40 AM
It is more or less like this
//Compute integer coordinates
int X=(int)texcoord_clamp(u * (float)texture_width);
int Y=(int)texcoord_clamp(s * (float)texture_height);
//Sample the texture
texel = texels[Y*texture_height+X*4];
texel = texels[Y*texture_height+X*4+1];
texel = texels[Y*texture_height+X*4+2];
texel = texels[Y*texture_height+X*4+3];
texcoord_clamp() would do the job of GL_CLAMP_TO_EDGE.
I'm also assuming GL_RGBA8 format.
This is like GL_NEAREST, GL_NEAREST filtering.
08-08-2008, 01:00 PM
Tex coords. can also wrap, so you should at least make sure they're within the range of 0 to 1,
or use some math to knock them back within range.
This should get rid of the integer part of a float:
uv - floor(uv);
That's of course if you have them set to WRAP instead of CLAMP.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.