Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions automap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ bool MiniMapArea::load()
//Create the sprite
// FIXME (nfries88): OpenGL does not work well when SDL is being used on the screen.
// this operation must be changed for GL engine to work.
SDL_Surface* s = m_bitmap->lockSurface();
auto s = m_bitmap->lockSurface();
for(int i = 0; i < 256; i++){
for(int j = 0; j < 256; j++){
uint8_t r, g, b;
getRGB(m_color[i][j], r, g, b);
m_bitmap->putPixel(i, j, SDL_MapRGB(s->format, r, g, b) ,s);
m_bitmap->putPixel(i, j, SDL_MapRGB(static_cast<SDLSurfaceStorage*>(s.get())->getSurface()->format, r, g, b) ,static_cast<SDLSurfaceStorage*>(s.get())->getSurface());
}
}
m_bitmap->unlockSurface();
Expand All @@ -142,10 +142,10 @@ void MiniMapArea::setTileColor(uint16_t x, uint16_t y, uint8_t color, uint8_t sp
m_speed[x][y] = speedindex;
//update the srpite
// FIXME (nfries88): Must be changed to engine-independent for OpenGL engine.
SDL_Surface* s = m_bitmap->lockSurface();
auto s = m_bitmap->lockSurface();
uint8_t r, g, b;
getRGB(color, r, g, b);
m_bitmap->putPixel(x, y, SDL_MapRGB(s->format, r, g, b) ,s);
m_bitmap->putPixel(x, y, SDL_MapRGB(static_cast<SDLSurfaceStorage*>(s.get())->getSurface()->format, r, g, b) ,static_cast<SDLSurfaceStorage*>(s.get())->getSurface());
m_bitmap->unlockSurface();
}

Expand Down
8 changes: 4 additions & 4 deletions engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,17 @@ Engine::Engine()

m_video_bpp = options.bpp;

m_screen = NULL;
m_screen = nullptr;

initFont(&m_sysfont, "system");
initFont(&m_minifont, "minifont");
initFont(&m_aafont, "aafont");
initFont(&m_gamefont, "gamefont");

m_fps = 0.;
m_ui = NULL;
m_light = NULL;
m_cursorBasic = m_cursorUse = NULL;
m_ui = nullptr;
m_light = nullptr;
m_cursorBasic = m_cursorUse = nullptr;

// remember default cursor
resetDefaultCursor();
Expand Down
81 changes: 81 additions & 0 deletions rgba_storage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#ifndef RGBA_STORAGE_H
#define RGBA_STORAGE_H

#include <memory>
#include <SDL.h>
#include <GL/gl.h>

class RGBAStorage {
public:
virtual ~RGBAStorage() = default;
virtual uint8_t* getData() = 0;
virtual int getWidth() const = 0;
virtual int getHeight() const = 0;
virtual int getPitch() const = 0;
};

class SDLSurfaceStorage : public RGBAStorage {
public:
SDLSurfaceStorage(SDL_Surface* surface) : surface_(surface) {}
~SDLSurfaceStorage() {
if (surface_) {
SDL_FreeSurface(surface_);
}
}

uint8_t* getData() override {
return static_cast<uint8_t*>(surface_->pixels);
}

int getWidth() const override {
return surface_->w;
}

int getHeight() const override {
return surface_->h;
}

int getPitch() const override {
return surface_->pitch;
}

private:
SDL_Surface* surface_;
};

class OpenGLTextureStorage : public RGBAStorage {
public:
OpenGLTextureStorage(GLuint texture, int width, int height)
: texture_(texture), width_(width), height_(height) {}

~OpenGLTextureStorage() {
if (texture_) {
glDeleteTextures(1, &texture_);
}
}

uint8_t* getData() override {
// OpenGL textures do not provide direct access to pixel data
return nullptr;
}

int getWidth() const override {
return width_;
}

int getHeight() const override {
return height_;
}

int getPitch() const override {
// OpenGL textures do not have a pitch value
return 0;
}

private:
GLuint texture_;
int width_;
int height_;
};

#endif // RGBA_STORAGE_H
Loading
Loading