back to normal blit, for this you need to use the funkey SDL library which has the corect alpha per-pixel alpha blending

Signed-off-by: Vincent-FK <vincent.buso@funkey-project.com>
This commit is contained in:
Vincent-FK 2019-10-22 19:10:08 +02:00
parent 6eb1a04901
commit ea42f62418
6 changed files with 78 additions and 32 deletions

2
.gitignore vendored
View File

@ -1,6 +1,7 @@
syntax: glob syntax: glob
*.orig *.orig
*.suo *.suo
*~
.git .git
Build/ Build/
Documentation/Documentation/* Documentation/Documentation/*
@ -9,4 +10,3 @@ Documentation/Manual/_build/*
Configuration/Configuration/bin/** Configuration/Configuration/bin/**
Configuration/Configuration/obj/** Configuration/Configuration/obj/**
Artifacts/** Artifacts/**

11
.project Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>funkey_retrofe</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>

View File

@ -50,6 +50,8 @@ if(WIN32)
find_package(SDL_ttf REQUIRED ) find_package(SDL_ttf REQUIRED )
find_package(SDL_gfx REQUIRED ) find_package(SDL_gfx REQUIRED )
find_package(ZLIB REQUIRED) find_package(ZLIB REQUIRED)
find_package(X11)
else() else()
include(FindPkgConfig) include(FindPkgConfig)
#pkg_search_module(SDL2 REQUIRED sdl2) #pkg_search_module(SDL2 REQUIRED sdl2)
@ -70,6 +72,8 @@ if(APPLE)
#find_package(SDL2 REQUIRED) #find_package(SDL2 REQUIRED)
find_package(SDL REQUIRED ) find_package(SDL REQUIRED )
endif() endif()
find_package(X11)
endif() endif()
set(RETROFE_INCLUDE_DIRS set(RETROFE_INCLUDE_DIRS
@ -88,6 +92,7 @@ set(RETROFE_INCLUDE_DIRS
"${ZLIB_INCLUDE_DIRS}" "${ZLIB_INCLUDE_DIRS}"
"${SQLITE3_ROOT}" "${SQLITE3_ROOT}"
"${RAPIDXML_ROOT}" "${RAPIDXML_ROOT}"
"${X11_INCLUDE_DIR}"
) )
if(MSVC) if(MSVC)
@ -107,6 +112,7 @@ set(RETROFE_LIBRARIES
${SDL_TTF_LIBRARIES} ${SDL_TTF_LIBRARIES}
${SDL_GFX_LIBRARIES} ${SDL_GFX_LIBRARIES}
${ZLIB_LIBRARIES} ${ZLIB_LIBRARIES}
${X11_LIBRARIES}
) )
if(NOT WIN32) if(NOT WIN32)
@ -224,7 +230,6 @@ set(RETROFE_SOURCES
set(EXECUTABLE_OUTPUT_PATH "${RETROFE_DIR}/Build" CACHE PATH "Build directory" FORCE) set(EXECUTABLE_OUTPUT_PATH "${RETROFE_DIR}/Build" CACHE PATH "Build directory" FORCE)
set(LIBRARY_OUTPUT_PATH "${RETROFE_DIR}/Build" CACHE PATH "Build directory" FORCE) set(LIBRARY_OUTPUT_PATH "${RETROFE_DIR}/Build" CACHE PATH "Build directory" FORCE)
include_directories(${RETROFE_INCLUDE_DIRS}) include_directories(${RETROFE_INCLUDE_DIRS})
add_executable(retrofe ${RETROFE_SOURCES} ${RETROFE_HEADERS}) add_executable(retrofe ${RETROFE_SOURCES} ${RETROFE_HEADERS})
target_link_libraries(retrofe ${RETROFE_LIBRARIES}) target_link_libraries(retrofe ${RETROFE_LIBRARIES})

View File

@ -18,7 +18,7 @@
#include "../Utility/Log.h" #include "../Utility/Log.h"
#include <SDL/SDL.h> #include <SDL/SDL.h>
#include <SDL/SDL_ttf.h> #include <SDL/SDL_ttf.h>
#include <SDL/SDL_gfxBlitFunc.h> //#include <SDL/SDL_gfxBlitFunc.h>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>

View File

@ -95,10 +95,25 @@ void RetroFE::render( )
//SDL_RenderClear( SDL::getRenderer( ) ); //SDL_RenderClear( SDL::getRenderer( ) );
SDL_FillRect(SDL::getWindow( ), NULL, SDL_MapRGB(SDL::getWindow( )->format, 0, 0, 0)); SDL_FillRect(SDL::getWindow( ), NULL, SDL_MapRGB(SDL::getWindow( )->format, 0, 0, 0));
uint32_t draw_ticks = SDL_GetTicks();
if ( currentPage_ ) if ( currentPage_ )
{ {
currentPage_->draw( ); currentPage_->draw( );
} }
int draw_time = SDL_GetTicks()-draw_ticks;
//printf("draw time: %dms\n", draw_time);
// DEBUG: Average draw time over FPS*5 frames
static int avg_draw_time = 0;
static int avg_draw_time_nb_vals = 0;
avg_draw_time += draw_time;
avg_draw_time_nb_vals++;
if(avg_draw_time_nb_vals >= FPS*5){
printf("Average draw time: %dms\n", avg_draw_time/avg_draw_time_nb_vals);
avg_draw_time=0;
avg_draw_time_nb_vals=0;
}
//SDL_RenderPresent( SDL::getRenderer( ) ); //SDL_RenderPresent( SDL::getRenderer( ) );
//SDL_Flip(SDL::getWindow( )); //SDL_Flip(SDL::getWindow( ));

View File

@ -182,15 +182,16 @@ bool SDL::initialize( Configuration &config )
} }
SDL_FillRect(window_virtual_, NULL, SDL_MapRGBA(window_virtual_->format, 0, 0, 0, 0)); SDL_FillRect(window_virtual_, NULL, SDL_MapRGBA(window_virtual_->format, 0, 0, 0, 0));
texture_copy_alpha_ = SDL_CreateRGBSurface(0, windowWidth_, windowHeight_, 32, rmask, gmask, bmask, amask); /*texture_copy_alpha_ = SDL_CreateRGBSurface(0, windowWidth_, windowHeight_, 32, rmask, gmask, bmask, amask);
if ( texture_copy_alpha_ == NULL ) if ( texture_copy_alpha_ == NULL )
{ {
std::string error = SDL_GetError( ); std::string error = SDL_GetError( );
Logger::write( Logger::ZONE_ERROR, "SDL", "SDL_CreateRGBSurface texture_copy_alpha_ failed: " + error ); Logger::write( Logger::ZONE_ERROR, "SDL", "SDL_CreateRGBSurface texture_copy_alpha_ failed: " + error );
retVal = false; retVal = false;
} }
SDL_FillRect(texture_copy_alpha_, NULL, SDL_MapRGBA(texture_copy_alpha_->format, 0, 0, 0, 0)); SDL_FillRect(texture_copy_alpha_, NULL, SDL_MapRGBA(texture_copy_alpha_->format, 0, 0, 0, 0));*/
} }
/*if ( retVal ) /*if ( retVal )
{ {
renderer_ = SDL_CreateRenderer( window_, -1, SDL_RENDERER_ACCELERATED ); renderer_ = SDL_CreateRenderer( window_, -1, SDL_RENDERER_ACCELERATED );
@ -271,11 +272,11 @@ bool SDL::deInitialize( )
window_virtual_ = NULL; window_virtual_ = NULL;
} }
if ( texture_copy_alpha_ ) /*if ( texture_copy_alpha_ )
{ {
SDL_FreeSurface(texture_copy_alpha_); SDL_FreeSurface(texture_copy_alpha_);
texture_copy_alpha_ = NULL; texture_copy_alpha_ = NULL;
} }*/
SDL_ShowCursor( SDL_TRUE ); SDL_ShowCursor( SDL_TRUE );
@ -569,22 +570,22 @@ bool SDL::renderCopy( SDL_Surface *texture, float alpha, SDL_Rect *src, SDL_Rect
/*SDL_SetAlpha(texture, SDL_SRCALPHA, static_cast<char>( alpha * 255 )); /*SDL_SetAlpha(texture, SDL_SRCALPHA, static_cast<char>( alpha * 255 ));
SDL_BlitSurface (texture, &srcRect, getWindow(), &dstRect);*/ SDL_BlitSurface (texture, &srcRect, getWindow(), &dstRect);*/
/*if(alpha){
unsigned int rmask; unsigned int rmask;
unsigned int gmask; unsigned int gmask;
unsigned int bmask; unsigned int bmask;
unsigned int amask; unsigned int amask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN #if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000; rmask = 0xff000000;
gmask = 0x00ff0000; gmask = 0x00ff0000;
bmask = 0x0000ff00; bmask = 0x0000ff00;
amask = 0x000000ff; amask = 0x000000ff;
#else #else
rmask = 0x000000ff; rmask = 0x000000ff;
gmask = 0x0000ff00; gmask = 0x0000ff00;
bmask = 0x00ff0000; bmask = 0x00ff0000;
amask = 0xff000000; amask = 0xff000000;
#endif #endif
SDL_Surface * texture_tmp = SDL_CreateRGBSurface(0, texture->w, texture->h, 32, rmask, gmask, bmask, amask); SDL_Surface * texture_tmp = SDL_CreateRGBSurface(0, texture->w, texture->h, 32, rmask, gmask, bmask, amask);
//SDL_FillRect(texture_tmp, NULL, SDL_MapRGBA(texture_tmp->format, 0, 0, 0, 0)); //SDL_FillRect(texture_tmp, NULL, SDL_MapRGBA(texture_tmp->format, 0, 0, 0, 0));
SDL_SetAlpha( texture, 0, SDL_ALPHA_OPAQUE ); SDL_SetAlpha( texture, 0, SDL_ALPHA_OPAQUE );
@ -593,6 +594,20 @@ bool SDL::renderCopy( SDL_Surface *texture, float alpha, SDL_Rect *src, SDL_Rect
//SDL_gfxBlitRGBA(texture_tmp, &srcRect, getWindow(), &dstRect); //SDL_gfxBlitRGBA(texture_tmp, &srcRect, getWindow(), &dstRect);
SDL_BlitSurface(texture_tmp, &srcRect, getWindow(), &dstRect); SDL_BlitSurface(texture_tmp, &srcRect, getWindow(), &dstRect);
SDL_FreeSurface(texture_tmp); SDL_FreeSurface(texture_tmp);
}*/
if(alpha){
SDL_SetAlpha(texture, SDL_SRCALPHA, static_cast<uint8_t>( alpha * 255 ));
//printf("\n-----------\n");
//printf("Alpha = %f = %u\n", alpha, texture->format->alpha);
SDL_BlitSurface(texture, &srcRect, getWindow(), &dstRect);
}
//texture = rotozoomSurfaceXY(texture, viewInfo.Angle, scaleX, scaleY, SMOOTHING_OFF); //texture = rotozoomSurfaceXY(texture, viewInfo.Angle, scaleX, scaleY, SMOOTHING_OFF);