Page 1 of 1

Shuffle Through pixels of image (OpenGL)

Posted: Thu Aug 25, 2011 4:40 am
by xx6heartless6xx
After I load an image in OpenGL I want to shuffle through the image and change the pixel color to another color or change its alpha. The problem is I don't know how to shuffle through in my loadImage function. I am loading the image in SDL first in case it matters. The commented part is where I need help on and here is what I have so far:

Code: Select all

SDL_Surface* surface = IMG_Load( "image.jpg" );

//Go through columns
for( int x = 0; x < surface->w; x++ ) {
	//Go through row
	for( int y = 0; y < surface->h; y++) {
		//NEED HELP HERE on how to change a pixel of surface
	}
}

Re: Shuffle Through pixels of image (OpenGL)

Posted: Thu Aug 25, 2011 8:12 am
by N64vSNES
I'm fairly sure this is what you're looking for:
http://lazyfoo.net/SDL_tutorials/lesson31/index.php

Re: Shuffle Through pixels of image (OpenGL)

Posted: Thu Aug 25, 2011 8:45 am
by Falco Girgis
xx6heartless6xx wrote:After I load an image in OpenGL I want to shuffle through the image and change the pixel color to another color or change its alpha. The problem is I don't know how to shuffle through in my loadImage function. I am loading the image in SDL first in case it matters. The commented part is where I need help on and here is what I have so far:

Code: Select all

SDL_Surface* surface = IMG_Load( "image.jpg" );

//Go through columns
for( int x = 0; x < surface->w; x++ ) {
	//Go through row
	for( int y = 0; y < surface->h; y++) {
		//NEED HELP HERE on how to change a pixel of surface
	}
}
That's a really, really bad idea first of all.

You should look into using a palette or a color look-up table instead. That way each pixel is just an index into a color, and you only modify the color in the table, rather than iterating through an entire texture to fuck with it.

Re: Shuffle Through pixels of image (OpenGL)

Posted: Thu Aug 25, 2011 4:07 pm
by xx6heartless6xx
N64vSNES wrote:I'm fairly sure this is what you're looking for:
http://lazyfoo.net/SDL_tutorials/lesson31/index.php
I've tried this before but its not working for me. The image just turns out the same or not at all.
GyroVorbis wrote:
xx6heartless6xx wrote:After I load an image in OpenGL I want to shuffle through the image and change the pixel color to another color or change its alpha. The problem is I don't know how to shuffle through in my loadImage function. I am loading the image in SDL first in case it matters. The commented part is where I need help on and here is what I have so far:

Code: Select all

SDL_Surface* surface = IMG_Load( "image.jpg" );

//Go through columns
for( int x = 0; x < surface->w; x++ ) {
	//Go through row
	for( int y = 0; y < surface->h; y++) {
		//NEED HELP HERE on how to change a pixel of surface
	}
}
That's a really, really bad idea first of all.

You should look into using a palette or a color look-up table instead. That way each pixel is just an index into a color, and you only modify the color in the table, rather than iterating through an entire texture to fuck with it.
Can you give me a simple example of how to do this? I'm still a beginner to opengl