Burbruee
Member
Hi,
I ordered a pandora last night and got so excited I started coding all night long. h34r:
Using SDL, and SDL_image respectively I can't seem to get transparency to work. I've used SDL in the past to work with transparent images, and never had an issue.
I've looked over my code again and again, even copied my loading code straight from lazyfoo. But it won't work so there must be something else causing this.
At first I thought maybe some setting in Photoshop prevented the transparency from being saved or something like that, but then I snagged another image from a project I worked on years ago and it has the same issue and there's nothing wrong with that image.
Using IMG_Load to load the png, linking with SDL_image.lib (using visual studio) I just don't see what's wrong.
Ends up looking like this:
Why does it get black around the sprite..? The image IS transparent..
Some code..
main.cpp:
engine probably don't need to be a pointer someone else pointed out, I'm still learning the language and cooked this up at 5 AM so don't complain.
Appreciate any help.. Thanks.
I ordered a pandora last night and got so excited I started coding all night long. h34r:
Using SDL, and SDL_image respectively I can't seem to get transparency to work. I've used SDL in the past to work with transparent images, and never had an issue.
I've looked over my code again and again, even copied my loading code straight from lazyfoo. But it won't work so there must be something else causing this.
At first I thought maybe some setting in Photoshop prevented the transparency from being saved or something like that, but then I snagged another image from a project I worked on years ago and it has the same issue and there's nothing wrong with that image.
Using IMG_Load to load the png, linking with SDL_image.lib (using visual studio) I just don't see what's wrong.
Ends up looking like this:
Why does it get black around the sprite..? The image IS transparent..
Some code..
main.cpp:
Code:
#include "engine.h"
#include "timer.h"
#include "sprite.h"
#include <iostream>
#include <fstream>
int main(int argc, char* argv[])
{
//Create the window and stuff
Engine *engine = new Engine();
engine->Create();
//Player sprite
Sprite spr(engine);
//LoadTexture runs engine->load_image which is same as lazy_foo with IMG_Load for sdl_image
spr.LoadTexture(engine, "Textures/player1.png");
//Color for background used later
Uint32 col = NULL;
while (engine->isRunning)
{
while (SDL_PollEvent(&engine->event))
{
if (engine->event.type == SDL_QUIT)
{
engine->isRunning = false;
}
if (engine->event.type == SDL_KEYDOWN)
{
switch(engine->event.key.keysym.sym)
{
case SDLK_ESCAPE:
engine->isRunning = false;
}
}
}
//This draws the gradient background, should put this in engine class
for (int y = 0; y < engine->SCR_H; y++)
{
col = SDL_MapRGB(engine->screen->format, 0, 0, 0 + (y * 160 / engine->SCR_H));
for (int x = 0; x < engine->SCR_W; x++)
{
engine->DrawPixel(engine->screen, x, y, col);
}
}
// Draw player, same as apply_surface on lazyfoo
engine->Draw(spr.getX(), spr.getY(), spr.player, engine->screen);
//Update screen
SDL_Flip(engine->screen);
}
delete engine;
return 0;
}
engine probably don't need to be a pointer someone else pointed out, I'm still learning the language and cooked this up at 5 AM so don't complain.
Appreciate any help.. Thanks.