Shuffle Through pixels of image (OpenGL)

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
xx6heartless6xx
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 80
Joined: Wed Feb 02, 2011 9:42 pm

Shuffle Through pixels of image (OpenGL)

Post 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
	}
}
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: Shuffle Through pixels of image (OpenGL)

Post by N64vSNES »

I'm fairly sure this is what you're looking for:
http://lazyfoo.net/SDL_tutorials/lesson31/index.php
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Shuffle Through pixels of image (OpenGL)

Post 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.
User avatar
xx6heartless6xx
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 80
Joined: Wed Feb 02, 2011 9:42 pm

Re: Shuffle Through pixels of image (OpenGL)

Post 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
Post Reply