Original Post
I am experimenting with bilinear filtering so I have two surfaces. The "noise" surface is loaded in. It is a bmp of a very noisey b&w. The other is "smoothed" which is where I'm putting the results of the filtering. Now noise will blit but smooth wont. What's weird is that I can pull a pixel from smoothed and it will be a normal value. Anyone see what's wrong? Ask about any functions that look confusing..
#pragma comment(lib,"SDL.lib")
#pragma comment(lib,"SDLMain.lib")
#include <sdl.h>
#include "SDL_Helper.h"
SDL_Surface *g_screen;
SDL_Surface *noise;
SDL_Surface *smoothed;
void BilinearFilter()
{
unsigned int pixel, right, bottom, dig;
pixel = right = bottom = dig = 0;
for(int x = 2; x < noise->w; x++)
{
for(int y = 2; y < noise->h; y++)
{
pixel = GetPixel(noise, x, y);
right = GetPixel(noise, x + 1, y);
bottom = GetPixel(noise, x, y - 1);
dig = GetPixel(noise, x - 1, y + 1);
pixel = (pixel + right + bottom + dig) / 4;
SetPixel(smoothed, x, y, pixel);
}
}
}
void Input()
{
unsigned char *keys = SDL_GetKeyState(0);
}
void Render()
{
SDL_FillRect(g_screen, 0, SDL_MapRGB(g_screen->format, 255,255,255));
SDL_Rect dest;
dest.x = 0;
dest.y = 0;
SDL_BlitSurface(noise, 0, g_screen, &dest);
dest.x = 300;
dest.y = 300;
SDL_BlitSurface(smoothed, 0, g_screen, &dest);
SDL_Flip(g_screen);
}
bool InitSDL()
{
noise = SDL_LoadBMP("noise.bmp");
SDL_Color color = {0,0,0,0};
smoothed = CreateEmptySurface(noise->w, noise->h, 24);
if(SDL_Init(SDL_INIT_VIDEO))
{
printf("Couldn't initalize SDL!");
return 0;
}
if((g_screen = SDL_SetVideoMode(640,480,24,SDL_SWSURFACE | SDL_DOUBLEBUF)) == NULL)
{
printf("Couldn't set video mode! Quitting...");
SDL_Quit();
return 0;
}
return 1;
}
bool MainLoop()
{
SDL_Event event;
while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_QUIT )
{
return false;
}
if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_ESCAPE )
{
return false;
}
}
}
Input();
Render();
return true;
}
int main(int argc, char** argv)
{
InitSDL();
BilinearFilter();
while(MainLoop())
SDL_FreeSurface(g_screen);
SDL_Quit();
return true;
}