• Create Account

### #Actualrocklobster

Posted 20 April 2012 - 07:22 AM

I've reworked my code from yesterday and i'm still getting some problems. I can get the image to draw, but the colors are usually just greyscale.
// my get colour at function
{
Uint32 pixel;
Uint8 red, green, blue;
RGBColour rgb;
pixel = getPixel(m_surface, x, y); //getPixel function is from http://www.libsdl.org/cgi/docwiki.cgi/Pixel_Access

SDL_LockSurface(m_surface);
SDL_GetRGB(pixel, m_surface->format, &red, &green, &blue);
SDL_UnlockSurface(m_surface);
rgb.r = red;
rgb.b = blue;
rgb.g = green;
return rgb;
}

// main part of the code, recreating the surface. I'm trying to recreate it because i will eventually be blending multiple textures based on height and i just // wanted to make sure i was getting color values correctly first.

for (int y = 0; y < reader->m_surface->h; y++)
{
for (int x = 0; x < 3 * reader->m_surface->w; x += 3)
{
int index = (y * reader->m_surface->w) + x;
newTexture[index] = colour.r;
newTexture[index + 1] = colour.g;
newTexture[index + 2] = colour.b;
}
}



### #6rocklobster

Posted 20 April 2012 - 07:21 AM

I've reworked my code from yesterday and i'm still getting some problems. I can get the image to draw, but the colors are usually just greyscale.
// my get colour at function
{
Uint32 pixel;
Uint8 red, green, blue;
RGBColour rgb;
pixel = getPixel(m_surface, x, y);

SDL_LockSurface(m_surface);
SDL_GetRGB(pixel, m_surface->format, &red, &green, &blue);
SDL_UnlockSurface(m_surface);
rgb.r = red;
rgb.b = blue;
rgb.g = green;
return rgb;
}
//getPixel function is from http://www.libsdl.org/cgi/docwiki.cgi/Pixel_Access
for (int y = 0; y < reader->m_surface->h; y++)
{
for (int x = 0; x < 3 * reader->m_surface->w; x += 3)
{
int index = (y * reader->m_surface->w) + x;
newTexture[index] = colour.r;
newTexture[index + 1] = colour.g;
newTexture[index + 2] = colour.b;
}
}



### #5rocklobster

Posted 20 April 2012 - 07:21 AM

I've reworked my code from yesterday and i'm still getting some problems. I can get the image to draw, but the colors are usually just greyscale.
// my get colour at function
{
Uint32 pixel;
Uint8 red, green, blue;
RGBColour rgb;
pixel = getPixel(m_surface, x, y);

SDL_LockSurface(m_surface);
SDL_GetRGB(pixel, m_surface->format, &red, &green, &blue);
SDL_UnlockSurface(m_surface);
rgb.r = red;
rgb.b = blue;
rgb.g = green;
return rgb;
}
getPixel function is from http://www.libsdl.org/cgi/docwiki.cgi/Pixel_Access
for (int y = 0; y < reader->m_surface->h; y++)
{
for (int x = 0; x < 3 * reader->m_surface->w; x += 3)
{
int index = (y * reader->m_surface->w) + x;
newTexture[index] = colour.r;
newTexture[index + 1] = colour.g;
newTexture[index + 2] = colour.b;
}
}



### #4rocklobster

Posted 20 April 2012 - 07:20 AM

I've reworked my code from yesterday and i'm still getting some problems.

// my get colour at function
{
Uint32 pixel;
Uint8 red, green, blue;
RGBColour rgb;
pixel = getPixel(m_surface, x, y);

SDL_LockSurface(m_surface);
SDL_GetRGB(pixel, m_surface->format, &red, &green, &blue);
SDL_UnlockSurface(m_surface);
rgb.r = red;
rgb.b = blue;
rgb.g = green;
return rgb;
}
getPixel function is from http://www.libsdl.org/cgi/docwiki.cgi/Pixel_Access
for (int y = 0; y < reader->m_surface->h; y++)
{
for (int x = 0; x < 3 * reader->m_surface->w; x += 3)
{
int index = (y * reader->m_surface->w) + x;
newTexture[index] = colour.r;
newTexture[index + 1] = colour.g;
newTexture[index + 2] = colour.b;
}
}



### #3rocklobster

Posted 19 April 2012 - 09:35 AM

I'm trying to modify this

http://www.libsdl.or..._Video#getpixel

to my needs.

EDIT: Just realised i mistyped my code in my first post. Double checked the alpha mask and it is 0.

unsigned int *p = (unsigned int*)m_surface->pixels;
int lineoffset = y * (m_surface->pitch / 3);
Uint32 pixels =  p[lineoffset + x];
Uint8 red;
Uint8 green;
Uint8 blue;
SDL_GetRGB(pixels, m_surface->format, &red, &green, &blue);
RGBColour rgb(red, green, blue);
return rgb;


I'm trying this and it seems to be working. Got some help from this thread http://www.gamedev.n...et-pixel-color/

### #2rocklobster

Posted 19 April 2012 - 09:34 AM

I'm trying to modify this

http://www.libsdl.or..._Video#getpixel

to my needs.

EDIT: Just realised i mistyped my code in my first post.

unsigned int *p = (unsigned int*)m_surface->pixels;
int lineoffset = y * (m_surface->pitch / 3);
Uint32 pixels =  p[lineoffset + x];
Uint8 red;
Uint8 green;
Uint8 blue;
SDL_GetRGB(pixels, m_surface->format, &red, &green, &blue);
RGBColour rgb(red, green, blue);
return rgb;


I'm trying this and it seems to be working. Got some help from this thread http://www.gamedev.net/topic/502040-sdl-get-pixel-color/

PARTNERS