?
Hallo
Ich habe mittels Tuts nun eine neue Klasse static_nonanimated_sprite geschrieben. Da ich aber viel Code nur kopiert habe, wollte ich diesen euch mal kurz vorstellen uzdn fragen, ob das so in Ordnung ist. Sprites werden angezeigt, aber ich suche nach eventuellen Grundsätzlichen Denkfehlern oder ähnlichem.
chrische::sdl::opengl::static_nonanimated_sprite::static_nonanimated_sprite()
{
}
chrische::sdl::opengl::static_nonanimated_sprite::~static_nonanimated_sprite()
{
glDeleteTextures(1, &texture);
}
void chrische::sdl::opengl::static_nonanimated_sprite::load( const std::string& file_name, const float pos_x, const float pos_y , const bool is_colorkeying, const int r, const int g, const int b)
{
SDL_Surface* p_temp_image = SDL_LoadBMP(file_name.c_str());
if(!p_temp_image)
{
std::cout<<"Fehler beim Laden von: "<<file_name<<std::endl<<"Fehlermeldung: "<<SDL_GetError()<<std::endl;
get_framework()->quit();
exit (1);
} // if(!p_image)
rect_.x = pos_x;
rect_.y = pos_y;
rect_.h = p_temp_image->h;
rect_.w = p_temp_image->w;
if(is_colorkeying)
{
Uint32 color = SDL_MapRGB(p_temp_image->format, static_cast<Uint8>(r), static_cast<Uint8>(g), static_cast<Uint8>(b));
SDL_SetColorKey(p_temp_image, SDL_SRCCOLORKEY, color);
}
SDL_Surface* p_bitmap = SDL_CreateRGBSurface(SDL_SWSURFACE, p_temp_image->w, p_temp_image->h, 32,
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
#else
0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
#endif
SDL_BlitSurface(p_temp_image, 0, p_bitmap, 0);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glPixelStorei(GL_UNPACK_ROW_LENGTH, p_bitmap->pitch / p_bitmap->format->BytesPerPixel);
int format = 0;
if (is_colorkeying)
format = 4;
else
format = 3;
glTexImage2D(GL_TEXTURE_2D, 0, format, p_bitmap->w, p_bitmap->h, 0, GL_RGBA,
GL_UNSIGNED_BYTE, p_bitmap->pixels);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
SDL_FreeSurface(p_bitmap);
SDL_FreeSurface(p_temp_image);
}
void chrische::sdl::opengl::static_nonanimated_sprite::render()
{
glColor3ub(255, 255, 255);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(rect_.x, rect_.y);
glTexCoord2f(1, 0); glVertex2i(rect_.w + rect_.x, rect_.y);
glTexCoord2f(1, 1); glVertex2i(rect_.w + rect_.x, rect_.h + rect_.y);
glTexCoord2f(0, 1); glVertex2i(rect_.x, rect_.h + rect_.y);
glEnd();
}
Vielen Dank für eure Mühe.
chrische