delete all OpenGL, GLES, Fluidsynth, mikmod, touchscreen, and mng code. these are all handled by SDL/SDL_mixer
This commit is contained in:
parent
6b73fd7b97
commit
dd9d287945
36 changed files with 374 additions and 5615 deletions
CMakeLists.txt
cmake/modules
src
game
guichan/opengl
include
map
stratagus
ui
unit
video
cursor.cppfont.cppgraphic.cpplinedraw.cppmng.cppmovie.cpppng.cppsdl.cppshaders.cppsprite.cppvideo.cpp
win32
|
@ -156,9 +156,6 @@ set(guichan_SRCS
|
|||
src/guichan/key.cpp
|
||||
src/guichan/keyinput.cpp
|
||||
src/guichan/mouseinput.cpp
|
||||
# src/guichan/opengl/opengl.cpp
|
||||
# src/guichan/opengl/openglgraphics.cpp
|
||||
# src/guichan/opengl/openglimageloader.cpp
|
||||
src/guichan/rectangle.cpp
|
||||
src/guichan/sdl/gsdl.cpp
|
||||
src/guichan/sdl/sdlgraphics.cpp
|
||||
|
@ -336,12 +333,9 @@ set(video_SRCS
|
|||
src/video/font.cpp
|
||||
src/video/graphic.cpp
|
||||
src/video/linedraw.cpp
|
||||
src/video/mng.cpp
|
||||
src/video/movie.cpp
|
||||
src/video/png.cpp
|
||||
src/video/sdl.cpp
|
||||
src/video/shaders.cpp
|
||||
src/video/sprite.cpp
|
||||
src/video/video.cpp
|
||||
)
|
||||
source_group(video FILES ${video_SRCS})
|
||||
|
@ -546,7 +540,6 @@ set(stratagus_generic_HDRS
|
|||
src/include/script.h
|
||||
src/include/script_sound.h
|
||||
src/include/settings.h
|
||||
src/include/shaders.h
|
||||
src/include/sound.h
|
||||
src/include/sound_server.h
|
||||
src/include/spells.h
|
||||
|
@ -638,17 +631,11 @@ if(WIN32)
|
|||
endif()
|
||||
|
||||
find_package(BZip2)
|
||||
find_package(FluidSynth)
|
||||
find_package(StackTrace)
|
||||
find_package(Mikmod)
|
||||
find_package(MNG)
|
||||
find_package(OggVorbis)
|
||||
find_package(Theora)
|
||||
|
||||
find_package(X11)
|
||||
find_package(OpenGL)
|
||||
find_package(OpenGLES)
|
||||
find_package(SDL_gles)
|
||||
|
||||
find_package(Sqlite)
|
||||
find_package(Doxygen)
|
||||
|
@ -680,9 +667,6 @@ endif()
|
|||
option(ENABLE_TOUCHSCREEN "Use touchscreen input" OFF)
|
||||
|
||||
option(WITH_BZIP2 "Compile Stratagus with BZip2 compression support" ON)
|
||||
option(WITH_FLUIDSYNTH "Compile Stratagus with FluidSynth sound library" ON)
|
||||
option(WITH_MIKMOD "Compile Stratagus with Mikmod sound library" ON)
|
||||
option(WITH_MNG "Compile Stratagus with MNG image library" ON)
|
||||
option(WITH_OGGVORBIS "Compile Stratagus with OGG/Vorbis sound library" ON)
|
||||
option(WITH_THEORA "Compile Stratagus with Theroa video library" ON)
|
||||
option(WITH_STACKTRACE "Compile Stratagus with StackTrace library" ON)
|
||||
|
@ -697,13 +681,7 @@ option(ENABLE_USEGAMEDIR "Place all files created by Stratagus(logs, savegames)
|
|||
option(ENABLE_MULTIBUILD "Compile Stratagus on all CPU cores simltaneously in MSVC" ON)
|
||||
|
||||
if(NOT WITH_RENDERER)
|
||||
if(OPENGL_FOUND AND FALSE)
|
||||
set(WITH_RENDERER "OpenGL")
|
||||
elseif(OPENGLES_FOUND AND SDLGLES_FOUND)
|
||||
set(WITH_RENDERER "OpenGLES")
|
||||
else()
|
||||
set(WITH_RENDERER "NativeSDL")
|
||||
endif()
|
||||
set(WITH_RENDERER "NativeSDL")
|
||||
endif()
|
||||
|
||||
# Install paths
|
||||
|
@ -737,32 +715,6 @@ if(WITH_BZIP2 AND BZIP2_FOUND)
|
|||
set(stratagus_LIBS ${stratagus_LIBS} ${BZIP2_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(WITH_FLUIDSYNTH AND FLUIDSYNTH_FOUND)
|
||||
add_definitions(-DUSE_FLUIDSYNTH ${FLUIDSYNTH_DEFINITIONS})
|
||||
include_directories(${FLUIDSYNTH_INCLUDE_DIR})
|
||||
set(stratagus_LIBS ${stratagus_LIBS} ${FLUIDSYNTH_LIBRARY})
|
||||
find_file(FLUIDSYNTH_DLL libfluidsynth.dll HINTS ${CMAKE_PREFIX_PATH}/bin)
|
||||
find_file(GLIB_DLL libglib-2.0-0.dll HINTS ${CMAKE_PREFIX_PATH} PATH_SUFFIXES bin lib)
|
||||
find_file(GTHREAD_DLL libgthread-2.0-0.dll HINTS ${CMAKE_PREFIX_PATH} PATH_SUFFIXES bin lib)
|
||||
set(MAKENSIS_FLAGS ${MAKENSIS_FLAGS} -DFLUID -DFLUIDDLL=libfluidsynth.dll -DGTHREADDLL=libglib-2.0-0.dll -DGLIBDLL=libgthread-2.0-0.dll)
|
||||
endif()
|
||||
|
||||
if(WITH_MIKMOD AND MIKMOD_FOUND)
|
||||
add_definitions(-DUSE_MIKMOD ${MIKMOD_DEFINITIONS})
|
||||
include_directories(${MIKMOD_INCLUDE_DIR})
|
||||
set(stratagus_LIBS ${stratagus_LIBS} ${MIKMOD_LIBRARY})
|
||||
endif()
|
||||
|
||||
if(WITH_MNG AND MNG_FOUND)
|
||||
add_definitions(-DUSE_MNG)
|
||||
include_directories(${MNG_INCLUDE_DIR})
|
||||
set(stratagus_LIBS ${stratagus_LIBS} ${MNG_LIBRARY})
|
||||
if (MSVC)
|
||||
include_directories(${JPEG_INCLUDE_DIR})
|
||||
set(stratagus_LIBS ${stratagus_LIBS} ${JPEG_LIBRARY})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(WITH_OGGVORBIS AND OGGVORBIS_FOUND)
|
||||
add_definitions(-DUSE_VORBIS)
|
||||
include_directories(${OGGVORBIS_INCLUDE_DIR})
|
||||
|
@ -787,28 +739,6 @@ if(WITH_X11 AND X11_FOUND)
|
|||
set(stratagus_LIBS ${stratagus_LIBS} ${X11_X11_LIB})
|
||||
endif()
|
||||
|
||||
if(WITH_RENDERER STREQUAL "OpenGL" AND OPENGL_FOUND)
|
||||
add_definitions(-DUSE_OPENGL)
|
||||
include_directories(${OPENGL_INCLUDE_DIR})
|
||||
set(stratagus_LIBS ${stratagus_LIBS} ${OPENGL_LIBRARIES})
|
||||
message(STATUS "Using OpenGL")
|
||||
elseif(WITH_RENDERER STREQUAL "OpenGLES" AND OPENGLES_FOUND AND SDLGLES_FOUND)
|
||||
if(SDLGLES_TYPE STREQUAL "Native")
|
||||
add_definitions(-DUSE_GLES_NATIVE)
|
||||
message(STATUS "Using OpenGLES (SDL Native)")
|
||||
elseif(SDLGLES_TYPE STREQUAL "EGL")
|
||||
add_definitions(-DUSE_GLES_EGL)
|
||||
message(STATUS "Using OpenGLES (SDL EGL)")
|
||||
else()
|
||||
message(FATAL_ERROR "Unknown SDL gles type")
|
||||
endif()
|
||||
add_definitions(-DUSE_GLES)
|
||||
include_directories(${OPENGLES_INCLUDE_DIR} ${SDLGLES_INCLUDE_DIR})
|
||||
set(stratagus_LIBS ${stratagus_LIBS} ${OPENGLES_LIBRARIES} ${SDLGLES_LIBRARY})
|
||||
elseif(NOT WITH_RENDERER STREQUAL "NativeSDL")
|
||||
message(FATAL_ERROR "Specified rendering support was not found in system.\nChoose: NativeSDL OpenGL OpenGLES")
|
||||
endif()
|
||||
|
||||
# Platform definitions
|
||||
|
||||
if(WIN32)
|
||||
|
@ -1027,22 +957,11 @@ else()
|
|||
endif()
|
||||
|
||||
log_package("Bzip2" "BZIP2")
|
||||
log_package("FluidSynth" "FLUIDSYNTH")
|
||||
log_package("MikMod" "MIKMOD")
|
||||
log_package("Mng" "MNG")
|
||||
log_package("Ogg/Vorbis" "OGGVORBIS")
|
||||
log_package("StackTrace" "STACKTRACE")
|
||||
log_package("Theora" "THEORA")
|
||||
log_package("X11" "X11")
|
||||
|
||||
if(WITH_RENDERER STREQUAL "OpenGL" AND OPENGL_FOUND)
|
||||
message("Renderer: OpenGL (Disable by param -DWITH_RENDERER=NativeSDL)")
|
||||
elseif(WITH_RENDERER STREQUAL "OpenGLES" AND OPENGLES_FOUND AND SDLGLES_FOUND)
|
||||
message("Renderer: OpenGLES (Disable by param -DWITH_RENDERER=NativeSDL)")
|
||||
else()
|
||||
message("Renderer: NativeSDL (Enable OpenGL by param -DWITH_RENDERER=OpenGL)")
|
||||
endif()
|
||||
|
||||
message("==================================")
|
||||
|
||||
# Compile Stratagus
|
||||
|
@ -1221,11 +1140,6 @@ endif()
|
|||
if(WIN32 AND ENABLE_NSIS AND MAKENSIS_FOUND)
|
||||
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/COPYING DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/win32/stratagus.ico DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||
if(WITH_FLUIDSYNTH AND FLUIDSYNTH_FOUND)
|
||||
file(COPY ${FLUIDSYNTH_DLL} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||
file(COPY ${GLIB_DLL} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||
file(COPY ${GTHREAD_DLL} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||
endif()
|
||||
# also ship lua51.dll
|
||||
find_file(LUA_DLL lua51.dll HINTS ${CMAKE_PREFIX_PATH} PATH_SUFFIXES bin lib)
|
||||
file(COPY ${LUA_DLL} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
# - Try to find the FluidSynth library
|
||||
# Once done this will define
|
||||
#
|
||||
# FLUIDSYNTH_FOUND - system has FluidSynth
|
||||
# FLUIDSYNTH_INCLUDE_DIR - the FLUIDSYNTH include directory
|
||||
# FLUIDSYNTH_LIBRARY - The FLUIDSYNTH library
|
||||
|
||||
# Copyright (c) 2014, cybermind <cybermindid@gmail.com>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
|
||||
if(FLUIDSYNTH_INCLUDE_DIR AND FLUIDSYNTH_LIBRARY)
|
||||
set(FLUIDSYNTH_FOUND true)
|
||||
else()
|
||||
find_path(FLUIDSYNTH_INCLUDE_DIR fluidsynth.h)
|
||||
find_library(FLUIDSYNTH_LIBRARY fluidsynth)
|
||||
|
||||
if(FLUIDSYNTH_INCLUDE_DIR AND FLUIDSYNTH_LIBRARY)
|
||||
set(FLUIDSYNTH_FOUND true)
|
||||
message(STATUS "Found FluidSynth: ${FLUIDSYNTH_LIBRARY}")
|
||||
else()
|
||||
set(FLUIDSYNTH_FOUND false)
|
||||
message(STATUS "Could not find FluidSynth")
|
||||
endif()
|
||||
|
||||
mark_as_advanced(FLUIDSYNTH_INCLUDE_DIR FLUIDSYNTH_LIBRARY)
|
||||
endif()
|
|
@ -1,42 +0,0 @@
|
|||
# - Try to find the MNG library
|
||||
# Once done this will define
|
||||
#
|
||||
# MNG_FOUND - system has Mikmod
|
||||
# MNG_INCLUDE_DIR - the Mikmod include directory
|
||||
# MNG_LIBRARY - The Mikmod library
|
||||
|
||||
# Copyright (c) 2011, Pali Rohár <pali.rohar@gmail.com>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
|
||||
if(MNG_INCLUDE_DIR AND MNG_LIBRARY AND ((NOT MSVC) OR (JPEG_INCLUDE_DIR AND JPEG_LIBRARY)))
|
||||
set(MNG_FOUND true)
|
||||
else()
|
||||
find_path(MNG_INCLUDE_DIR libmng.h)
|
||||
find_library(MNG_LIBRARY NAMES mng)
|
||||
if(MSVC)
|
||||
find_path(JPEG_INCLUDE_DIR jpeglib.h)
|
||||
find_library(JPEG_LIBRARY NAMES jpeg)
|
||||
endif()
|
||||
|
||||
if(MNG_INCLUDE_DIR AND MNG_LIBRARY AND ((NOT MSVC) OR (JPEG_INCLUDE_DIR AND JPEG_LIBRARY)))
|
||||
set(MNG_FOUND true)
|
||||
message(STATUS "Found MNG: ${MNG_LIBRARY}")
|
||||
if (MSVC)
|
||||
message(STATUS "Found JPEG: ${JPEG_LIBRARY}")
|
||||
endif()
|
||||
else()
|
||||
set(MNG_FOUND false)
|
||||
if(MSVC AND (NOT (JPEG_INCLUDE_DIR AND JPEG_LIBRARY)))
|
||||
message(STATUS "Could not find JPEG")
|
||||
endif()
|
||||
message(STATUS "Could not find MNG")
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
mark_as_advanced(MNG_INCLUDE_DIR MNG_LIBRARY JPEG_INCLUDE_DIR JPEG_LIBRARY)
|
||||
else()
|
||||
mark_as_advanced(MNG_INCLUDE_DIR MNG_LIBRARY)
|
||||
endif()
|
||||
endif()
|
|
@ -1,28 +0,0 @@
|
|||
# - Try to find the Mikmod library
|
||||
# Once done this will define
|
||||
#
|
||||
# MIKMOD_FOUND - system has Mikmod
|
||||
# MIKMOD_INCLUDE_DIR - the Mikmod include directory
|
||||
# MIKMOD_LIBRARY - The Mikmod library
|
||||
|
||||
# Copyright (c) 2011, Pali Rohár <pali.rohar@gmail.com>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
|
||||
if(MIKMOD_INCLUDE_DIR AND MIKMOD_LIBRARY)
|
||||
set(MIKMOD_FOUND true)
|
||||
else()
|
||||
find_path(MIKMOD_INCLUDE_DIR mikmod.h)
|
||||
find_library(MIKMOD_LIBRARY NAMES mikmod)
|
||||
|
||||
if(MIKMOD_INCLUDE_DIR AND MIKMOD_LIBRARY)
|
||||
set(MIKMOD_FOUND true)
|
||||
message(STATUS "Found Mikmod: ${MIKMOD_LIBRARY}")
|
||||
else()
|
||||
set(MIKMOD_FOUND false)
|
||||
message(STATUS "Could not find Mikmod")
|
||||
endif()
|
||||
|
||||
mark_as_advanced(MIKMOD_INCLUDE_DIR MIKMOD_LIBRARY)
|
||||
endif()
|
|
@ -1,106 +0,0 @@
|
|||
#-------------------------------------------------------------------
|
||||
# This file is part of the CMake build system for OGRE
|
||||
# (Object-oriented Graphics Rendering Engine)
|
||||
# For the latest info, see http://www.ogre3d.org/
|
||||
#
|
||||
# The contents of this file are placed in the public domain. Feel
|
||||
# free to make use of it in any way you like.
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
# Copyright (c) 2011, Pali Rohár <pali.rohar@gmail.com>
|
||||
# Modified:
|
||||
# * Search for EGL library
|
||||
# * Show staus message
|
||||
# * Cleaned code
|
||||
|
||||
# - Try to find OpenGLES
|
||||
# Once done this will define
|
||||
#
|
||||
# OPENGLES_FOUND - system has OpenGLES
|
||||
# OPENGLES_INCLUDE_DIR - the GL include directory
|
||||
# OPENGLES_LIBRARIES - Link these to use OpenGLES
|
||||
|
||||
if(OPENGLES_INCLUDE_DIR AND OPENGLES_LIBRARIES)
|
||||
set(OPENGLES_FOUND true)
|
||||
else()
|
||||
|
||||
if(WIN32)
|
||||
|
||||
if(CYGWIN)
|
||||
find_path(OPENGLES_INCLUDE_DIR GLES/gl.h)
|
||||
find_library(OPENGLES_GL_LIBRARY libgles_cm)
|
||||
find_library(OPENGLES_EGL_LIBRARY EGL)
|
||||
elseif(BORLAND)
|
||||
set(OPENGLES_GL_LIBRARY import32 CACHE STRING "OpenGL ES 1.x library for win32")
|
||||
# TODO: EGL
|
||||
else()
|
||||
# MS compiler - todo - fix the following line:
|
||||
set(OPENGLES_GL_LIBRARY libgles_cm.lib CACHE STRING "OpenGL ES 1.x library for win32")
|
||||
# TODO: EGL
|
||||
endif()
|
||||
|
||||
elseif(APPLE)
|
||||
|
||||
|
||||
set(OPENGLES_GL_LIBRARY "-framework OpenGLES")
|
||||
# TODO: EGL
|
||||
|
||||
elseif(SYMBIAN)
|
||||
|
||||
set(ORIGINAL_CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH})
|
||||
set(CMAKE_PREFIX_PATH ${CMAKE_SYSYEM_OUT_DIR})
|
||||
find_library(OPENGLES_gl_LIBRARY libgles_cm)
|
||||
set(CMAKE_PREFIX_PATH ${ORIGINAL_CMAKE_PREFIX_PATH})
|
||||
# TODO: EGL
|
||||
|
||||
else()
|
||||
|
||||
find_path(OPENGLES_INCLUDE_DIR GLES/gl.h
|
||||
/usr/openwin/share/include
|
||||
/opt/graphics/OpenGL/include
|
||||
/usr/X11R6/include
|
||||
/usr/include
|
||||
)
|
||||
|
||||
find_library(OPENGLES_GL_LIBRARY NAMES GLES_CM GLESv1_CM PATHS
|
||||
/usr/openwin/lib
|
||||
/opt/graphics/OpenGL/lib
|
||||
/usr/shlib
|
||||
/usr/X11R6/lib
|
||||
/usr/lib
|
||||
)
|
||||
|
||||
find_library(OPENGLES_EGL_LIBRARY NAMES EGL PATHS
|
||||
/usr/openwin/lib
|
||||
/opt/graphics/OpenGL/lib
|
||||
/usr/shlib
|
||||
/usr/X11R6/lib
|
||||
/usr/lib
|
||||
)
|
||||
|
||||
# On Unix OpenGL most certainly always requires X11.
|
||||
# Feel free to tighten up these conditions if you don't
|
||||
# think this is always true.
|
||||
|
||||
find_package(X11)
|
||||
|
||||
if(X11_FOUND)
|
||||
set(OPENGLES_LIBRARIES ${OPENGLES_LIBRARIES} ${X11_LIBRARIES})
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
if(OPENGLES_EGL_LIBRARY AND OPENGLES_GL_LIBRARY)
|
||||
set(OPENGLES_LIBRARIES ${OPENGLES_LIBRARIES} ${OPENGLES_EGL_LIBRARY} ${OPENGLES_GL_LIBRARY})
|
||||
set(OPENGLES_FOUND true)
|
||||
message(STATUS "Found OpenGL ES 1.1 libraries: ${OPENGLES_LIBRARIES}")
|
||||
else()
|
||||
unset(OPENGLES_LIBRARIES)
|
||||
unset(OPENGLES_INCLUDE_DIR)
|
||||
set(OPENGLES_FOUND false)
|
||||
message(STATUS "Could not find OpenGL ES 1.1 libraries")
|
||||
endif()
|
||||
|
||||
mark_as_advanced(OPENGLES_INCLUDE_DIR OPENGLES_LIBRARIES)
|
||||
|
||||
endif()
|
|
@ -1,58 +0,0 @@
|
|||
# - Try to detect some SDL gles support
|
||||
# Once done this will define
|
||||
#
|
||||
# SDLGLES_FOUND - system has gles support in SDL
|
||||
# SDLGLES_TYPE - Native or EGL
|
||||
# SDLGLES_INCLUDE_DIR - include directory for SDL gles (can be empty)
|
||||
# SDLGLES_LIBRARY - library for SDL gles (can be empty)
|
||||
|
||||
# Types:
|
||||
# Native - support is in SDL, program only needs to add SDL_OPENGLES flag to SDL_SetVideoMode
|
||||
# EGL - support using directly EGL library, see http://pandorawiki.org/Combining_OpenGL_ES_1.1_and_SDL_to_create_a_window_on_the_Pandora
|
||||
# program needs to initialize EGL and GLES manually
|
||||
|
||||
# Copyright (c) 2011-2013, Pali Rohár <pali.rohar@gmail.com>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
|
||||
set(SDLGLES_FOUND false)
|
||||
|
||||
if(SDLGLES_TYPE)
|
||||
set(SDLGLES_FOUND true)
|
||||
else()
|
||||
if (NOT SDLGLES_FOUND)
|
||||
# Check for Native support
|
||||
include(CheckTypeSize)
|
||||
|
||||
set(CMAKE_REQUIRED_INCLUDES SDL include/SDL)
|
||||
set(CMAKE_EXTRA_INCLUDE_FILES SDL_video.h)
|
||||
check_type_size(SDL_OPENGLES, SDLGLES_NATIVE)
|
||||
|
||||
if(HAVE_SDLGLES_NATIVE)
|
||||
set(SDLGLES_FOUND true)
|
||||
set(SDLGLES_TYPE "Native")
|
||||
set(SDLGLES_INCLUDE_DIR "")
|
||||
set(SDLGLES_LIBRARY "")
|
||||
message(STATUS "Found Native SDL gles")
|
||||
else()
|
||||
message(STATUS "Could not find Native SDL gles")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (NOT SDLGLES_FOUND)
|
||||
# Check for EGL support
|
||||
find_package(OpenGLES)
|
||||
if(OPENGLES_FOUND)
|
||||
set(SDLGLES_FOUND true)
|
||||
set(SDLGLES_TYPE "EGL")
|
||||
set(SDLGLES_INCLUDE_DIR "")
|
||||
set(SDLGLES_LIBRARY "")
|
||||
message(STATUS "Found EGL SDL gles")
|
||||
else()
|
||||
message(STATUS "Could not find EGL SDL gles")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
mark_as_advanced(SDLGLES_TYPE SDLGLES_INCLUDE_DIR SDLGLES_LIBRARY)
|
||||
endif()
|
|
@ -298,103 +298,53 @@ static void WriteMapPreview(const char *mapname, CMap &map)
|
|||
png_write_info(png_ptr, info_ptr);
|
||||
|
||||
const int rectSize = 5; // size of rectange used for player start spots
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
unsigned char *pixels = new unsigned char[UI.Minimap.W * UI.Minimap.H * 3];
|
||||
if (!pixels) {
|
||||
fprintf(stderr, "Out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
// Copy GL map surface to pixel array
|
||||
for (int i = 0; i < UI.Minimap.H; ++i) {
|
||||
for (int j = 0; j < UI.Minimap.W; ++j) {
|
||||
Uint32 c = ((Uint32 *)MinimapSurfaceGL)[j + i * UI.Minimap.W];
|
||||
const int offset = (i * UI.Minimap.W + j) * 3;
|
||||
pixels[offset + 0] = ((c & RMASK) >> RSHIFT);
|
||||
pixels[offset + 1] = ((c & GMASK) >> GSHIFT);
|
||||
pixels[offset + 2] = ((c & BMASK) >> BSHIFT);
|
||||
}
|
||||
}
|
||||
// Add player start spots
|
||||
for (int i = 0; i < PlayerMax - 1; ++i) {
|
||||
if (Players[i].Type != PlayerNobody) {
|
||||
for (int j = -rectSize / 2; j <= rectSize / 2; ++j) {
|
||||
for (int k = -rectSize / 2; k <= rectSize / 2; ++k) {
|
||||
const int miniMapX = Players[i].StartPos.x * UI.Minimap.W / map.Info.MapWidth;
|
||||
const int miniMapY = Players[i].StartPos.y * UI.Minimap.H / map.Info.MapHeight;
|
||||
if (miniMapX + j < 0 || miniMapX + j >= UI.Minimap.W) {
|
||||
continue;
|
||||
}
|
||||
if (miniMapY + k < 0 || miniMapY + k >= UI.Minimap.H) {
|
||||
continue;
|
||||
}
|
||||
const int offset = ((miniMapY + k) * UI.Minimap.H + miniMapX + j) * 3;
|
||||
pixels[offset + 0] = ((Players[i].Color & RMASK) >> RSHIFT);
|
||||
pixels[offset + 1] = ((Players[i].Color & GMASK) >> GSHIFT);
|
||||
pixels[offset + 2] = ((Players[i].Color & BMASK) >> BSHIFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Write everything in PNG
|
||||
for (int i = 0; i < UI.Minimap.H; ++i) {
|
||||
unsigned char *row = new unsigned char[UI.Minimap.W * 3];
|
||||
memcpy(row, pixels + i * UI.Minimap.W * 3, UI.Minimap.W * 3);
|
||||
png_write_row(png_ptr, row);
|
||||
delete[] row;
|
||||
}
|
||||
delete[] pixels;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
unsigned char *row = new unsigned char[UI.Minimap.W * 3];
|
||||
const SDL_PixelFormat *fmt = MinimapSurface->format;
|
||||
SDL_Surface *preview = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
||||
UI.Minimap.W, UI.Minimap.H, 32, fmt->Rmask, fmt->Gmask, fmt->Bmask, 0);
|
||||
SDL_BlitSurface(MinimapSurface, NULL, preview, NULL);
|
||||
unsigned char *row = new unsigned char[UI.Minimap.W * 3];
|
||||
const SDL_PixelFormat *fmt = MinimapSurface->format;
|
||||
SDL_Surface *preview = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
||||
UI.Minimap.W, UI.Minimap.H, 32, fmt->Rmask, fmt->Gmask, fmt->Bmask, 0);
|
||||
SDL_BlitSurface(MinimapSurface, NULL, preview, NULL);
|
||||
|
||||
SDL_LockSurface(preview);
|
||||
SDL_LockSurface(preview);
|
||||
|
||||
SDL_Rect rect;
|
||||
for (int i = 0; i < PlayerMax - 1; ++i) {
|
||||
if (Players[i].Type != PlayerNobody) {
|
||||
rect.x = Players[i].StartPos.x * UI.Minimap.W / map.Info.MapWidth - rectSize / 2;
|
||||
rect.y = Players[i].StartPos.y * UI.Minimap.H / map.Info.MapHeight - rectSize / 2;
|
||||
rect.w = rect.h = rectSize;
|
||||
SDL_FillRect(preview, &rect, Players[i].Color);
|
||||
}
|
||||
SDL_Rect rect;
|
||||
for (int i = 0; i < PlayerMax - 1; ++i) {
|
||||
if (Players[i].Type != PlayerNobody) {
|
||||
rect.x = Players[i].StartPos.x * UI.Minimap.W / map.Info.MapWidth - rectSize / 2;
|
||||
rect.y = Players[i].StartPos.y * UI.Minimap.H / map.Info.MapHeight - rectSize / 2;
|
||||
rect.w = rect.h = rectSize;
|
||||
SDL_FillRect(preview, &rect, Players[i].Color);
|
||||
}
|
||||
|
||||
for (int i = 0; i < UI.Minimap.H; ++i) {
|
||||
switch (preview->format->BytesPerPixel) {
|
||||
case 1:
|
||||
for (int j = 0; j < UI.Minimap.W; ++j) {
|
||||
Uint8 c = ((Uint8 *)preview->pixels)[j + i * UI.Minimap.W];
|
||||
row[j * 3 + 0] = fmt->palette->colors[c].r;
|
||||
row[j * 3 + 1] = fmt->palette->colors[c].g;
|
||||
row[j * 3 + 2] = fmt->palette->colors[c].b;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
memcpy(row, (char *)preview->pixels + i * UI.Minimap.W, UI.Minimap.W * 3);
|
||||
break;
|
||||
case 4:
|
||||
for (int j = 0; j < UI.Minimap.W; ++j) {
|
||||
Uint32 c = ((Uint32 *)preview->pixels)[j + i * UI.Minimap.W];
|
||||
row[j * 3 + 0] = ((c & fmt->Rmask) >> fmt->Rshift);
|
||||
row[j * 3 + 1] = ((c & fmt->Gmask) >> fmt->Gshift);
|
||||
row[j * 3 + 2] = ((c & fmt->Bmask) >> fmt->Bshift);
|
||||
}
|
||||
break;
|
||||
}
|
||||
png_write_row(png_ptr, row);
|
||||
}
|
||||
delete[] row;
|
||||
|
||||
SDL_UnlockSurface(preview);
|
||||
SDL_FreeSurface(preview);
|
||||
}
|
||||
|
||||
for (int i = 0; i < UI.Minimap.H; ++i) {
|
||||
switch (preview->format->BytesPerPixel) {
|
||||
case 1:
|
||||
for (int j = 0; j < UI.Minimap.W; ++j) {
|
||||
Uint8 c = ((Uint8 *)preview->pixels)[j + i * UI.Minimap.W];
|
||||
row[j * 3 + 0] = fmt->palette->colors[c].r;
|
||||
row[j * 3 + 1] = fmt->palette->colors[c].g;
|
||||
row[j * 3 + 2] = fmt->palette->colors[c].b;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
memcpy(row, (char *)preview->pixels + i * UI.Minimap.W, UI.Minimap.W * 3);
|
||||
break;
|
||||
case 4:
|
||||
for (int j = 0; j < UI.Minimap.W; ++j) {
|
||||
Uint32 c = ((Uint32 *)preview->pixels)[j + i * UI.Minimap.W];
|
||||
row[j * 3 + 0] = ((c & fmt->Rmask) >> fmt->Rshift);
|
||||
row[j * 3 + 1] = ((c & fmt->Gmask) >> fmt->Gshift);
|
||||
row[j * 3 + 2] = ((c & fmt->Bmask) >> fmt->Bshift);
|
||||
}
|
||||
break;
|
||||
}
|
||||
png_write_row(png_ptr, row);
|
||||
}
|
||||
delete[] row;
|
||||
|
||||
SDL_UnlockSurface(preview);
|
||||
SDL_FreeSurface(preview);
|
||||
|
||||
png_write_end(png_ptr, info_ptr);
|
||||
|
||||
/* clean up after the write, and free any memory allocated */
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
/* _______ __ __ __ ______ __ __ _______ __ __
|
||||
* / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
|
||||
* / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
|
||||
* / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
|
||||
* / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
|
||||
* /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
|
||||
* \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
|
||||
*
|
||||
* Copyright (c) 2004, 2005 darkbits Js_./
|
||||
* Per Larsson a.k.a finalman _RqZ{a<^_aa
|
||||
* Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a//
|
||||
* _Qhm`] _f "'c 1!5m
|
||||
* Visit: http://guichan.darkbits.org )Qk<P ` _: :+' .' "{[
|
||||
* .)j(] .d_/ '-( P . S
|
||||
* License: (BSD) <Td/Z <fP"5(\"??"\a. .L
|
||||
* Redistribution and use in source and _dV>ws?a-?' ._/L #'
|
||||
* binary forms, with or without )4d[#7r, . ' )d`)[
|
||||
* modification, are permitted provided _Q-5'5W..j/?' -?!\)cam'
|
||||
* that the following conditions are met: j<<WP+k/);. _W=j f
|
||||
* 1. Redistributions of source code must .$%w\/]Q . ."' . mj$
|
||||
* retain the above copyright notice, ]E.pYY(Q]>. a J@\
|
||||
* this list of conditions and the j(]1u<sE"L,. . ./^ ]{a
|
||||
* following disclaimer. 4'_uomm\. )L);-4 (3=
|
||||
* 2. Redistributions in binary form must )_]X{Z('a_"a7'<a"a, ]"[
|
||||
* reproduce the above copyright notice, #}<]m7`Za??4,P-"'7. ).m
|
||||
* this list of conditions and the ]d2e)Q(<Q( ?94 b- LQ/
|
||||
* following disclaimer in the <B!</]C)d_, '(<' .f. =C+m
|
||||
* documentation and/or other materials .Z!=J ]e []('-4f _ ) -.)m]'
|
||||
* provided with the distribution. .w[5]' _[ /.)_-"+? _/ <W"
|
||||
* 3. Neither the name of Guichan nor the :$we` _! + _/ . j?
|
||||
* names of its contributors may be used =3)= _f (_yQmWW$#( "
|
||||
* to endorse or promote products derived - W, sQQQQmZQ#Wwa]..
|
||||
* from this software without specific (js, \[QQW$QWW#?!V"".
|
||||
* prior written permission. ]y:.<\.. .
|
||||
* -]n w/ ' [.
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT )/ )/ !
|
||||
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY < (; sac , '
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, ]^ .- %
|
||||
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF c < r
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR aga< <La
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 5% )P'-3L
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR _bQf` y`..)a
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, ,J?4P'.P"_(\?d'.,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES _Pa,)!f/<[]/ ?"
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT _2-..:. .r+_,.. .
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ?a.<%"' " -'.a_ _,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ^
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* For comments regarding functions please see the header file.
|
||||
*/
|
||||
|
||||
#include "guichan/opengl.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void gcnOpenGL() { }
|
||||
}
|
|
@ -1,331 +0,0 @@
|
|||
/* _______ __ __ __ ______ __ __ _______ __ __
|
||||
* / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
|
||||
* / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
|
||||
* / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
|
||||
* / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
|
||||
* /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
|
||||
* \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
|
||||
*
|
||||
* Copyright (c) 2004, 2005 darkbits Js_./
|
||||
* Per Larsson a.k.a finalman _RqZ{a<^_aa
|
||||
* Olof Naess<EFBFBD>n a.k.a jansem/yakslem _asww7!uY`> )\a//
|
||||
* _Qhm`] _f "'c 1!5m
|
||||
* Visit: http://guichan.darkbits.org )Qk<P ` _: :+' .' "{[
|
||||
* .)j(] .d_/ '-( P . S
|
||||
* License: (BSD) <Td/Z <fP"5(\"??"\a. .L
|
||||
* Redistribution and use in source and _dV>ws?a-?' ._/L #'
|
||||
* binary forms, with or without )4d[#7r, . ' )d`)[
|
||||
* modification, are permitted provided _Q-5'5W..j/?' -?!\)cam'
|
||||
* that the following conditions are met: j<<WP+k/);. _W=j f
|
||||
* 1. Redistributions of source code must .$%w\/]Q . ."' . mj$
|
||||
* retain the above copyright notice, ]E.pYY(Q]>. a J@\
|
||||
* this list of conditions and the j(]1u<sE"L,. . ./^ ]{a
|
||||
* following disclaimer. 4'_uomm\. )L);-4 (3=
|
||||
* 2. Redistributions in binary form must )_]X{Z('a_"a7'<a"a, ]"[
|
||||
* reproduce the above copyright notice, #}<]m7`Za??4,P-"'7. ).m
|
||||
* this list of conditions and the ]d2e)Q(<Q( ?94 b- LQ/
|
||||
* following disclaimer in the <B!</]C)d_, '(<' .f. =C+m
|
||||
* documentation and/or other materials .Z!=J ]e []('-4f _ ) -.)m]'
|
||||
* provided with the distribution. .w[5]' _[ /.)_-"+? _/ <W"
|
||||
* 3. Neither the name of Guichan nor the :$we` _! + _/ . j?
|
||||
* names of its contributors may be used =3)= _f (_yQmWW$#( "
|
||||
* to endorse or promote products derived - W, sQQQQmZQ#Wwa]..
|
||||
* from this software without specific (js, \[QQW$QWW#?!V"".
|
||||
* prior written permission. ]y:.<\.. .
|
||||
* -]n w/ ' [.
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT )/ )/ !
|
||||
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY < (; sac , '
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, ]^ .- %
|
||||
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF c < r
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR aga< <La
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 5% )P'-3L
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR _bQf` y`..)a
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, ,J?4P'.P"_(\?d'.,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES _Pa,)!f/<[]/ ?"
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT _2-..:. .r+_,.. .
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ?a.<%"' " -'.a_ _,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ^
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* For comments regarding functions please see the header file.
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifdef __amigaos4__
|
||||
#include <mgl/gl.h>
|
||||
#define glVertex3i glVertex3f
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "guichan/opengl/openglgraphics.h"
|
||||
#include "guichan/exception.h"
|
||||
|
||||
|
||||
namespace gcn
|
||||
{
|
||||
OpenGLGraphics::OpenGLGraphics()
|
||||
{
|
||||
setTargetPlane(640, 480);
|
||||
mAlpha = false;
|
||||
}
|
||||
|
||||
OpenGLGraphics::OpenGLGraphics(int width, int height)
|
||||
{
|
||||
setTargetPlane(width, height);
|
||||
}
|
||||
|
||||
OpenGLGraphics::~OpenGLGraphics()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void OpenGLGraphics::_beginDraw()
|
||||
{
|
||||
glPushAttrib(
|
||||
GL_COLOR_BUFFER_BIT |
|
||||
GL_CURRENT_BIT |
|
||||
GL_DEPTH_BUFFER_BIT |
|
||||
GL_ENABLE_BIT |
|
||||
GL_FOG_BIT |
|
||||
GL_LIGHTING_BIT |
|
||||
GL_LINE_BIT |
|
||||
GL_POINT_BIT |
|
||||
GL_POLYGON_BIT |
|
||||
GL_SCISSOR_BIT |
|
||||
GL_STENCIL_BUFFER_BIT |
|
||||
GL_TEXTURE_BIT |
|
||||
GL_TRANSFORM_BIT
|
||||
);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
glMatrixMode(GL_TEXTURE);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
glOrtho(0.0, (double)mWidth, (double)mHeight, 0.0, -1.0, 1.0);
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
|
||||
pushClipArea(Rectangle(0, 0, mWidth, mHeight));
|
||||
}
|
||||
|
||||
void OpenGLGraphics::_endDraw()
|
||||
{
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
|
||||
glMatrixMode(GL_TEXTURE);
|
||||
glPopMatrix();
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
|
||||
glPopAttrib();
|
||||
|
||||
popClipArea();
|
||||
}
|
||||
|
||||
bool OpenGLGraphics::pushClipArea(Rectangle area)
|
||||
{
|
||||
bool result = Graphics::pushClipArea(area);
|
||||
|
||||
glScissor(mClipStack.top().x,
|
||||
mHeight - mClipStack.top().y - mClipStack.top().height,
|
||||
mClipStack.top().width,
|
||||
mClipStack.top().height);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void OpenGLGraphics::popClipArea()
|
||||
{
|
||||
Graphics::popClipArea();
|
||||
|
||||
if (mClipStack.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
glScissor(mClipStack.top().x,
|
||||
mHeight - mClipStack.top().y - mClipStack.top().height,
|
||||
mClipStack.top().width,
|
||||
mClipStack.top().height);
|
||||
}
|
||||
|
||||
void OpenGLGraphics::setTargetPlane(int width, int height)
|
||||
{
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
}
|
||||
|
||||
void OpenGLGraphics::drawImage(const Image* image, int srcX, int srcY,
|
||||
int dstX, int dstY, int width,
|
||||
int height)
|
||||
{
|
||||
dstX += mClipStack.top().xOffset;
|
||||
dstY += mClipStack.top().yOffset;
|
||||
|
||||
// The following code finds the real width and height of the texture.
|
||||
// OpenGL only supports texture sizes that are powers of two
|
||||
int realImageWidth = 1;
|
||||
int realImageHeight = 1;
|
||||
while (realImageWidth < image->getWidth())
|
||||
{
|
||||
realImageWidth *= 2;
|
||||
}
|
||||
while (realImageHeight < image->getHeight())
|
||||
{
|
||||
realImageHeight *= 2;
|
||||
}
|
||||
|
||||
// Find OpenGL texture coordinates
|
||||
float texX1 = srcX / (float)realImageWidth;
|
||||
float texY1 = srcY / (float)realImageHeight;
|
||||
float texX2 = (srcX+width) / (float)realImageWidth;
|
||||
float texY2 = (srcY+height) / (float)realImageHeight;
|
||||
|
||||
// Please dont look too closely at the next line, it is not pretty.
|
||||
// It uses the image data as a pointer to a GLuint
|
||||
glBindTexture(GL_TEXTURE_2D, *((GLuint *)(image->_getData())));
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
// Check if blending already is enabled
|
||||
if (!mAlpha)
|
||||
{
|
||||
glEnable(GL_BLEND);
|
||||
}
|
||||
|
||||
// Draw a textured quad -- the image
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(texX1, texY1);
|
||||
glVertex3i(dstX, dstY, 0);
|
||||
|
||||
glTexCoord2f(texX1, texY2);
|
||||
glVertex3i(dstX, dstY + height, 0);
|
||||
|
||||
glTexCoord2f(texX2, texY2);
|
||||
glVertex3i(dstX + width, dstY + height, 0);
|
||||
|
||||
glTexCoord2f(texX2, texY1);
|
||||
glVertex3i(dstX + width, dstY, 0);
|
||||
glEnd();
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
// Don't disable blending if the color has alpha
|
||||
if (!mAlpha)
|
||||
{
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGLGraphics::drawPoint(int x, int y)
|
||||
{
|
||||
x += mClipStack.top().xOffset;
|
||||
y += mClipStack.top().yOffset;
|
||||
|
||||
glBegin(GL_POINTS);
|
||||
glVertex3i(x, y, 0);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void OpenGLGraphics::drawLine(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
x1 += mClipStack.top().xOffset;
|
||||
y1 += mClipStack.top().yOffset;
|
||||
x2 += mClipStack.top().xOffset;
|
||||
y2 += mClipStack.top().yOffset;
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glVertex3f(x1+0.5f, y1+0.5f, 0);
|
||||
glVertex3f(x2+0.5f, y2+0.5f, 0);
|
||||
glEnd();
|
||||
|
||||
glBegin(GL_POINTS);
|
||||
glVertex3f(x2+0.5f, y2+0.5f, 0);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void OpenGLGraphics::drawRectangle(const Rectangle& rectangle)
|
||||
{
|
||||
glBegin(GL_LINE_LOOP);
|
||||
glVertex3f(rectangle.x + mClipStack.top().xOffset + 0.5f,
|
||||
rectangle.y + mClipStack.top().yOffset + 0.5f, 0);
|
||||
glVertex3f(rectangle.x + rectangle.width - 0.5f + mClipStack.top().xOffset,
|
||||
rectangle.y + mClipStack.top().yOffset + 0.5f, 0);
|
||||
glVertex3f(rectangle.x + rectangle.width - 0.5f + mClipStack.top().xOffset,
|
||||
rectangle.y + rectangle.height + mClipStack.top().yOffset - 0.5f, 0);
|
||||
glVertex3f(rectangle.x + mClipStack.top().xOffset + 0.5f,
|
||||
rectangle.y + rectangle.height + mClipStack.top().yOffset - 0.5f, 0);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void OpenGLGraphics::fillRectangle(const Rectangle& rectangle)
|
||||
{
|
||||
glBegin(GL_QUADS);
|
||||
glVertex3i(rectangle.x + mClipStack.top().xOffset,
|
||||
rectangle.y + mClipStack.top().yOffset, 0);
|
||||
glVertex3i(rectangle.x + rectangle.width + mClipStack.top().xOffset,
|
||||
rectangle.y + mClipStack.top().yOffset, 0);
|
||||
glVertex3i(rectangle.x + rectangle.width + mClipStack.top().xOffset,
|
||||
rectangle.y + rectangle.height + mClipStack.top().yOffset, 0);
|
||||
glVertex3i(rectangle.x + mClipStack.top().xOffset,
|
||||
rectangle.y + rectangle.height + mClipStack.top().yOffset, 0);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void OpenGLGraphics::setColor(const Color& color)
|
||||
{
|
||||
mColor = color;
|
||||
glColor4f(color.r/255.0f,
|
||||
color.g/255.0f,
|
||||
color.b/255.0f,
|
||||
color.a/255.0f);
|
||||
|
||||
mAlpha = color.a != 255;
|
||||
|
||||
if (mAlpha)
|
||||
{
|
||||
glEnable(GL_BLEND);
|
||||
}
|
||||
}
|
||||
|
||||
const Color& OpenGLGraphics::getColor()
|
||||
{
|
||||
return mColor;
|
||||
}
|
||||
}
|
|
@ -1,271 +0,0 @@
|
|||
/* _______ __ __ __ ______ __ __ _______ __ __
|
||||
* / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
|
||||
* / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
|
||||
* / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
|
||||
* / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
|
||||
* /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
|
||||
* \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
|
||||
*
|
||||
* Copyright (c) 2004, 2005 darkbits Js_./
|
||||
* Per Larsson a.k.a finalman _RqZ{a<^_aa
|
||||
* Olof Naess<EFBFBD>n a.k.a jansem/yakslem _asww7!uY`> )\a//
|
||||
* _Qhm`] _f "'c 1!5m
|
||||
* Visit: http://guichan.darkbits.org )Qk<P ` _: :+' .' "{[
|
||||
* .)j(] .d_/ '-( P . S
|
||||
* License: (BSD) <Td/Z <fP"5(\"??"\a. .L
|
||||
* Redistribution and use in source and _dV>ws?a-?' ._/L #'
|
||||
* binary forms, with or without )4d[#7r, . ' )d`)[
|
||||
* modification, are permitted provided _Q-5'5W..j/?' -?!\)cam'
|
||||
* that the following conditions are met: j<<WP+k/);. _W=j f
|
||||
* 1. Redistributions of source code must .$%w\/]Q . ."' . mj$
|
||||
* retain the above copyright notice, ]E.pYY(Q]>. a J@\
|
||||
* this list of conditions and the j(]1u<sE"L,. . ./^ ]{a
|
||||
* following disclaimer. 4'_uomm\. )L);-4 (3=
|
||||
* 2. Redistributions in binary form must )_]X{Z('a_"a7'<a"a, ]"[
|
||||
* reproduce the above copyright notice, #}<]m7`Za??4,P-"'7. ).m
|
||||
* this list of conditions and the ]d2e)Q(<Q( ?94 b- LQ/
|
||||
* following disclaimer in the <B!</]C)d_, '(<' .f. =C+m
|
||||
* documentation and/or other materials .Z!=J ]e []('-4f _ ) -.)m]'
|
||||
* provided with the distribution. .w[5]' _[ /.)_-"+? _/ <W"
|
||||
* 3. Neither the name of Guichan nor the :$we` _! + _/ . j?
|
||||
* names of its contributors may be used =3)= _f (_yQmWW$#( "
|
||||
* to endorse or promote products derived - W, sQQQQmZQ#Wwa]..
|
||||
* from this software without specific (js, \[QQW$QWW#?!V"".
|
||||
* prior written permission. ]y:.<\.. .
|
||||
* -]n w/ ' [.
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT )/ )/ !
|
||||
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY < (; sac , '
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, ]^ .- %
|
||||
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF c < r
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR aga< <La
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 5% )P'-3L
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR _bQf` y`..)a
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, ,J?4P'.P"_(\?d'.,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES _Pa,)!f/<[]/ ?"
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT _2-..:. .r+_,.. .
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ?a.<%"' " -'.a_ _,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ^
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* For comments regarding functions please see the header file.
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifdef __amigaos4__
|
||||
#include <mgl/gl.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#include "guichan/opengl/openglimageloader.h"
|
||||
#include "guichan/exception.h"
|
||||
|
||||
namespace gcn
|
||||
{
|
||||
|
||||
OpenGLImageLoader::OpenGLImageLoader()
|
||||
{
|
||||
mImageLoader = 0;
|
||||
}
|
||||
|
||||
OpenGLImageLoader::OpenGLImageLoader(ImageLoader* imageLoader)
|
||||
{
|
||||
mImageLoader = imageLoader;
|
||||
}
|
||||
|
||||
void OpenGLImageLoader::setHostImageLoader(ImageLoader* imageLoader)
|
||||
{
|
||||
mImageLoader = imageLoader;
|
||||
}
|
||||
|
||||
void OpenGLImageLoader::prepare(const std::string& filename)
|
||||
{
|
||||
if(mImageLoader == NULL)
|
||||
{
|
||||
throw GCN_EXCEPTION("No host ImageLoader present.");
|
||||
}
|
||||
|
||||
mImageLoader->prepare(filename);
|
||||
}
|
||||
|
||||
void* OpenGLImageLoader::getRawData()
|
||||
{
|
||||
if(mImageLoader == NULL)
|
||||
{
|
||||
throw GCN_EXCEPTION("No host ImageLoader present.");
|
||||
}
|
||||
|
||||
return mImageLoader->getRawData();
|
||||
}
|
||||
|
||||
void* OpenGLImageLoader::finalize()
|
||||
{
|
||||
if(mImageLoader == NULL)
|
||||
{
|
||||
throw GCN_EXCEPTION("No host ImageLoader present.");
|
||||
}
|
||||
|
||||
unsigned int *rawData = (unsigned int *)mImageLoader->getRawData();
|
||||
int width = mImageLoader->getWidth();
|
||||
int height = mImageLoader->getHeight();
|
||||
int realWidth = 1, realHeight = 1;
|
||||
|
||||
while(realWidth < width)
|
||||
{
|
||||
realWidth *= 2;
|
||||
}
|
||||
|
||||
while(realHeight < height)
|
||||
{
|
||||
realHeight *= 2;
|
||||
}
|
||||
|
||||
unsigned int *realData = new unsigned int[realWidth*realHeight];
|
||||
int x, y;
|
||||
|
||||
for (y = 0; y < realHeight; y++)
|
||||
{
|
||||
for (x = 0; x < realWidth; x++)
|
||||
{
|
||||
if (x < width && y < height)
|
||||
{
|
||||
if (rawData[x+y*width] == 0xffff00ff)
|
||||
{
|
||||
realData[x+y*realWidth] = 0x00000000;
|
||||
}
|
||||
else
|
||||
{
|
||||
realData[x+y*realWidth] = rawData[x+y*width];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
realData[x+y*realWidth] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GLuint *texture = new GLuint[1];
|
||||
glGenTextures(1, texture);
|
||||
glBindTexture(GL_TEXTURE_2D, *texture);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
4,
|
||||
realWidth,
|
||||
realHeight,
|
||||
0,
|
||||
GL_RGBA,
|
||||
GL_UNSIGNED_BYTE,
|
||||
realData);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
||||
|
||||
delete[] realData;
|
||||
mImageLoader->discard();
|
||||
|
||||
GLenum error = glGetError();
|
||||
if (error)
|
||||
{
|
||||
std::string errmsg;
|
||||
switch (error)
|
||||
{
|
||||
case GL_INVALID_ENUM:
|
||||
errmsg = "GL_INVALID_ENUM";
|
||||
break;
|
||||
|
||||
case GL_INVALID_VALUE:
|
||||
errmsg = "GL_INVALID_VALUE";
|
||||
break;
|
||||
|
||||
case GL_INVALID_OPERATION:
|
||||
errmsg = "GL_INVALID_OPERATION";
|
||||
break;
|
||||
|
||||
case GL_STACK_OVERFLOW:
|
||||
errmsg = "GL_STACK_OVERFLOW";
|
||||
break;
|
||||
|
||||
case GL_STACK_UNDERFLOW:
|
||||
errmsg = "GL_STACK_UNDERFLOW";
|
||||
break;
|
||||
|
||||
case GL_OUT_OF_MEMORY:
|
||||
errmsg = "GL_OUT_OF_MEMORY";
|
||||
break;
|
||||
}
|
||||
|
||||
throw GCN_EXCEPTION(std::string("glGetError said: ") + errmsg);
|
||||
}
|
||||
|
||||
return (void *)texture;
|
||||
}
|
||||
|
||||
void OpenGLImageLoader::discard()
|
||||
{
|
||||
if(mImageLoader == NULL)
|
||||
{
|
||||
throw GCN_EXCEPTION("No host ImageLoader present.");
|
||||
}
|
||||
|
||||
mImageLoader->discard();
|
||||
}
|
||||
|
||||
void OpenGLImageLoader::free(Image* image)
|
||||
{
|
||||
glDeleteTextures(1, (GLuint *)image->_getData());
|
||||
|
||||
delete[] (GLuint *)(image->_getData());
|
||||
}
|
||||
|
||||
int OpenGLImageLoader::getWidth() const
|
||||
{
|
||||
if(mImageLoader == NULL)
|
||||
{
|
||||
throw GCN_EXCEPTION("No host ImageLoader present.");
|
||||
}
|
||||
|
||||
return mImageLoader->getWidth();
|
||||
}
|
||||
|
||||
int OpenGLImageLoader::getHeight() const
|
||||
{
|
||||
if(mImageLoader == NULL)
|
||||
{
|
||||
throw GCN_EXCEPTION("No host ImageLoader present.");
|
||||
}
|
||||
|
||||
return mImageLoader->getHeight();
|
||||
}
|
||||
|
||||
Color OpenGLImageLoader::getPixel(int x, int y)
|
||||
{
|
||||
if(mImageLoader == NULL)
|
||||
{
|
||||
throw GCN_EXCEPTION("No host ImageLoader present.");
|
||||
}
|
||||
|
||||
return mImageLoader->getPixel(x, y);
|
||||
}
|
||||
|
||||
void OpenGLImageLoader::putPixel(int x, int y, const Color& color)
|
||||
{
|
||||
if(mImageLoader == NULL)
|
||||
{
|
||||
throw GCN_EXCEPTION("No host ImageLoader present.");
|
||||
}
|
||||
|
||||
mImageLoader->putPixel(x, y, color);
|
||||
}
|
||||
}
|
|
@ -96,9 +96,6 @@ public:
|
|||
|
||||
void Load();
|
||||
void Reload() const;
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
void FreeOpenGL();
|
||||
#endif
|
||||
void Clean();
|
||||
|
||||
CGraphic *GetFontColorGraphic(const CFontColor &fontColor) const;
|
||||
|
@ -109,9 +106,6 @@ public:
|
|||
void DynamicLoad() const;
|
||||
|
||||
private:
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
void MakeFontColorTextures() const;
|
||||
#endif
|
||||
void MeasureWidths();
|
||||
|
||||
private:
|
||||
|
@ -175,13 +169,6 @@ extern int GetHotKey(const std::string &text);
|
|||
/// Load and initialize the fonts
|
||||
extern void LoadFonts();
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
/// Free OpenGL fonts
|
||||
extern void FreeOpenGLFonts();
|
||||
/// Reload OpenGL fonts
|
||||
extern void ReloadFonts();
|
||||
#endif
|
||||
|
||||
/// Cleanup the font module
|
||||
extern void CleanFonts();
|
||||
|
||||
|
|
|
@ -63,10 +63,6 @@ public:
|
|||
void UpdateSeenXY(const Vec2i &) {}
|
||||
void Update();
|
||||
void Create();
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
void FreeOpenGL();
|
||||
void Reload();
|
||||
#endif
|
||||
void Destroy();
|
||||
void Draw() const;
|
||||
void DrawViewportArea(const CViewport &viewport) const;
|
||||
|
@ -89,13 +85,6 @@ public:
|
|||
bool UpdateCache;
|
||||
};
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
// Minimap surface with units (for OpenGL)
|
||||
extern unsigned char *MinimapSurfaceGL;
|
||||
// Minimap surface with terrain only (for OpenGL)
|
||||
extern unsigned char *MinimapTerrainSurfaceGL;
|
||||
#endif
|
||||
|
||||
// Minimap surface with units (for software)
|
||||
extern SDL_Surface *MinimapSurface;
|
||||
// Minimap surface with terrain only (for software)
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
#ifndef __SHADERS_H__
|
||||
#define __SHADERS_H__
|
||||
#ifdef USE_OPENGL
|
||||
#define MAX_SHADERS 5
|
||||
// #define SHADERDEBUG // Uncomment for loading shaders from file
|
||||
#ifndef __APPLE__
|
||||
extern PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebuffer;
|
||||
#else
|
||||
#define glBindFramebuffer glBindFramebufferEXT
|
||||
#endif
|
||||
extern GLuint fullscreenFramebuffer;
|
||||
extern bool LoadShaders(int direction, char* shadernameOut);
|
||||
extern bool LoadShaderExtensions();
|
||||
extern void SetupFramebuffer();
|
||||
extern void RenderFramebufferToScreen();
|
||||
#endif
|
||||
#endif
|
|
@ -35,19 +35,6 @@
|
|||
|
||||
#include "SDL.h"
|
||||
|
||||
#ifdef USE_GLES
|
||||
#include "GLES/gl.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
#ifdef __APPLE__
|
||||
#define GL_GLEXT_PROTOTYPES 1
|
||||
#endif
|
||||
#define __gl_glext_h_
|
||||
#include "SDL_opengl.h"
|
||||
#include "shaders.h"
|
||||
#endif
|
||||
|
||||
#include "guichan.h"
|
||||
|
||||
#include "color.h"
|
||||
|
@ -55,13 +42,6 @@
|
|||
|
||||
class CFont;
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
extern char ForceUseOpenGL;
|
||||
extern bool UseOpenGL;
|
||||
extern bool ZoomNoResize;
|
||||
extern bool GLShaderPipelineSupported;
|
||||
#endif
|
||||
|
||||
class CGraphic : public gcn::Image
|
||||
{
|
||||
|
||||
|
@ -74,10 +54,6 @@ protected:
|
|||
CGraphic() : Surface(NULL), SurfaceFlip(NULL), frame_map(NULL),
|
||||
Width(0), Height(0), NumFrames(1), GraphicWidth(0), GraphicHeight(0),
|
||||
Refs(1), Resized(false)
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
, TextureWidth(0.f), TextureHeight(0.f), Textures(NULL), NumTextures(0),
|
||||
ColorCyclingTextures(NULL), NumColorCycles(0)
|
||||
#endif
|
||||
{
|
||||
frameFlip_map = NULL;
|
||||
}
|
||||
|
@ -95,18 +71,12 @@ public:
|
|||
|
||||
// Draw frame
|
||||
void DrawFrame(unsigned frame, int x, int y) const;
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
void DoDrawFrameClip(GLuint *textures, unsigned frame, int x, int y) const;
|
||||
#endif
|
||||
void DrawFrameClip(unsigned frame, int x, int y) const;
|
||||
void DrawFrameTrans(unsigned frame, int x, int y, int alpha) const;
|
||||
void DrawFrameClipTrans(unsigned frame, int x, int y, int alpha) const;
|
||||
|
||||
// Draw frame flipped horizontally
|
||||
void DrawFrameX(unsigned frame, int x, int y) const;
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
void DoDrawFrameClipX(GLuint *textures, unsigned frame, int x, int y) const;
|
||||
#endif
|
||||
void DrawFrameClipX(unsigned frame, int x, int y) const;
|
||||
void DrawFrameTransX(unsigned frame, int x, int y, int alpha) const;
|
||||
void DrawFrameClipTransX(unsigned frame, int x, int y, int alpha) const;
|
||||
|
@ -117,9 +87,6 @@ public:
|
|||
static CGraphic *Get(const std::string &file);
|
||||
|
||||
static void Free(CGraphic *g);
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
bool DeleteColorCyclingTextures();
|
||||
#endif
|
||||
|
||||
void Load(bool grayscale = false);
|
||||
void Flip();
|
||||
|
@ -151,15 +118,6 @@ public:
|
|||
int Refs; /// Uses of this graphic
|
||||
bool Resized; /// Image has been resized
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
GLfloat TextureWidth; /// Width of the texture
|
||||
GLfloat TextureHeight; /// Height of the texture
|
||||
GLuint *Textures; /// Texture names
|
||||
int NumTextures; /// Number of textures
|
||||
GLuint **ColorCyclingTextures; /// Texture names
|
||||
int NumColorCycles; /// Number of color cycled texture groups
|
||||
#endif
|
||||
|
||||
friend class CFont;
|
||||
};
|
||||
|
||||
|
@ -168,9 +126,6 @@ class CPlayerColorGraphic : public CGraphic
|
|||
protected:
|
||||
CPlayerColorGraphic()
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
memset(PlayerColorTextures, 0, sizeof(PlayerColorTextures));
|
||||
#endif
|
||||
}
|
||||
|
||||
public:
|
||||
|
@ -182,10 +137,6 @@ public:
|
|||
static CPlayerColorGraphic *Get(const std::string &file);
|
||||
|
||||
CPlayerColorGraphic *Clone(bool grayscale = false) const;
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
GLuint *PlayerColorTextures[PlayerMax];/// Textures with player colors
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef USE_MNG
|
||||
|
@ -207,11 +158,6 @@ public:
|
|||
unsigned char *buffer;
|
||||
unsigned long ticks;
|
||||
int iteration;
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
GLfloat texture_width; /// Width of the texture
|
||||
GLfloat texture_height; /// Height of the texture
|
||||
GLuint texture_name; /// Texture name
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -316,14 +262,7 @@ public:
|
|||
|
||||
inline Uint32 MapRGB(SDL_PixelFormat *f, Uint8 r, Uint8 g, Uint8 b)
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
return MapRGBA(f, r, g, b, 0xFF);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
return SDL_MapRGB(f, r, g, b);
|
||||
}
|
||||
return SDL_MapRGB(f, r, g, b);
|
||||
}
|
||||
inline Uint32 MapRGB(SDL_PixelFormat *f, const CColor &color)
|
||||
{
|
||||
|
@ -331,14 +270,7 @@ public:
|
|||
}
|
||||
inline Uint32 MapRGBA(SDL_PixelFormat *f, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
return ((r << RSHIFT) | (g << GSHIFT) | (b << BSHIFT) | (a << ASHIFT));
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
return SDL_MapRGBA(f, r, g, b, a);
|
||||
}
|
||||
return SDL_MapRGBA(f, r, g, b, a);
|
||||
}
|
||||
inline Uint32 MapRGBA(SDL_PixelFormat *f, const CColor &color)
|
||||
{
|
||||
|
@ -346,30 +278,11 @@ public:
|
|||
}
|
||||
inline void GetRGB(Uint32 c, SDL_PixelFormat *f, Uint8 *r, Uint8 *g, Uint8 *b)
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
*r = (c >> RSHIFT) & 0xff;
|
||||
*g = (c >> GSHIFT) & 0xff;
|
||||
*b = (c >> BSHIFT) & 0xff;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
SDL_GetRGB(c, f, r, g, b);
|
||||
}
|
||||
SDL_GetRGB(c, f, r, g, b);
|
||||
}
|
||||
inline void GetRGBA(Uint32 c, SDL_PixelFormat *f, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
*r = (c >> RSHIFT) & 0xff;
|
||||
*g = (c >> GSHIFT) & 0xff;
|
||||
*b = (c >> BSHIFT) & 0xff;
|
||||
*a = (c >> ASHIFT) & 0xff;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
SDL_GetRGBA(c, f, r, g, b, a);
|
||||
}
|
||||
SDL_GetRGBA(c, f, r, g, b, a);
|
||||
}
|
||||
|
||||
int Width;
|
||||
|
@ -416,17 +329,6 @@ extern SDL_Window *TheWindow;
|
|||
extern SDL_Renderer *TheRenderer;
|
||||
extern SDL_Surface *TheScreen;
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
/// Max texture size supported on the video card
|
||||
extern GLint GLMaxTextureSize;
|
||||
/// User-specified limit for ::GLMaxTextureSize
|
||||
extern GLint GLMaxTextureSizeOverride;
|
||||
/// Is OpenGL texture compression supported
|
||||
extern bool GLTextureCompressionSupported;
|
||||
/// Use OpenGL texture compression
|
||||
extern bool UseGLTextureCompression;
|
||||
#endif
|
||||
|
||||
/// register lua function
|
||||
extern void VideoCclRegister();
|
||||
|
||||
|
@ -442,25 +344,6 @@ extern int VideoValidResolution(int w, int h);
|
|||
/// Load graphic from PNG file
|
||||
extern int LoadGraphicPNG(CGraphic *g);
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
|
||||
/// Make an OpenGL texture
|
||||
extern void MakeTexture(CGraphic *graphic);
|
||||
/// Make an OpenGL texture of the player color pixels only.
|
||||
extern void MakePlayerColorTexture(CPlayerColorGraphic *graphic, int player);
|
||||
|
||||
/// Regenerate Window screen if needed
|
||||
extern void ValidateOpenGLScreen();
|
||||
|
||||
/// Free OpenGL graphics
|
||||
extern void FreeOpenGLGraphics();
|
||||
/// Reload OpenGL graphics
|
||||
extern void ReloadGraphics();
|
||||
/// Reload OpenGL
|
||||
extern void ReloadOpenGL();
|
||||
|
||||
#endif
|
||||
|
||||
/// Initializes video synchronization.
|
||||
extern void SetVideoSync();
|
||||
|
||||
|
@ -557,25 +440,8 @@ inline int GetColorIndexByName(const char *colorName) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
void DrawTexture(const CGraphic *g, GLuint *textures, int sx, int sy,
|
||||
int ex, int ey, int x, int y, int flip);
|
||||
#endif
|
||||
|
||||
extern void FreeGraphics();
|
||||
|
||||
|
||||
// ARB_texture_compression
|
||||
#if defined(USE_OPENGL) && !defined(__APPLE__)
|
||||
extern PFNGLCOMPRESSEDTEXIMAGE3DARBPROC glCompressedTexImage3DARB;
|
||||
extern PFNGLCOMPRESSEDTEXIMAGE2DARBPROC glCompressedTexImage2DARB;
|
||||
extern PFNGLCOMPRESSEDTEXIMAGE1DARBPROC glCompressedTexImage1DARB;
|
||||
extern PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC glCompressedTexSubImage3DARB;
|
||||
extern PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC glCompressedTexSubImage2DARB;
|
||||
extern PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC glCompressedTexSubImage1DARB;
|
||||
extern PFNGLGETCOMPRESSEDTEXIMAGEARBPROC glGetCompressedTexImageARB;
|
||||
#endif
|
||||
|
||||
//
|
||||
// Color Cycling stuff
|
||||
//
|
||||
|
|
|
@ -52,29 +52,6 @@ public:
|
|||
virtual ~LuaActionListener();
|
||||
};
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
class MyOpenGLGraphics : public gcn::Graphics
|
||||
{
|
||||
public:
|
||||
virtual void _beginDraw();
|
||||
virtual void _endDraw();
|
||||
|
||||
virtual void drawImage(const gcn::Image *image, int srcX, int srcY,
|
||||
int dstX, int dstY, int width, int height);
|
||||
|
||||
virtual void drawPoint(int x, int y);
|
||||
virtual void drawLine(int x1, int y1, int x2, int y2);
|
||||
virtual void drawRectangle(const gcn::Rectangle &rectangle);
|
||||
virtual void fillRectangle(const gcn::Rectangle &rectangle);
|
||||
|
||||
virtual void setColor(const gcn::Color &color) { mColor = color; }
|
||||
virtual const gcn::Color &getColor() { return mColor; }
|
||||
|
||||
private:
|
||||
gcn::Color mColor;
|
||||
};
|
||||
#endif
|
||||
|
||||
class ImageWidget : public gcn::Icon
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -424,36 +424,28 @@ void UpdateFogOfWarChange()
|
|||
*/
|
||||
void VideoDrawOnlyFog(int x, int y)
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
Video.FillRectangleClip(Video.MapRGBA(0, 0, 0, 0, FogOfWarOpacity),
|
||||
x, y, PixelTileSize.x, PixelTileSize.y);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
int oldx;
|
||||
int oldy;
|
||||
SDL_Rect srect;
|
||||
SDL_Rect drect;
|
||||
int oldx;
|
||||
int oldy;
|
||||
SDL_Rect srect;
|
||||
SDL_Rect drect;
|
||||
|
||||
srect.x = 0;
|
||||
srect.y = 0;
|
||||
srect.w = OnlyFogSurface->w;
|
||||
srect.h = OnlyFogSurface->h;
|
||||
srect.x = 0;
|
||||
srect.y = 0;
|
||||
srect.w = OnlyFogSurface->w;
|
||||
srect.h = OnlyFogSurface->h;
|
||||
|
||||
oldx = x;
|
||||
oldy = y;
|
||||
CLIP_RECTANGLE(x, y, srect.w, srect.h);
|
||||
srect.x += x - oldx;
|
||||
srect.y += y - oldy;
|
||||
oldx = x;
|
||||
oldy = y;
|
||||
CLIP_RECTANGLE(x, y, srect.w, srect.h);
|
||||
srect.x += x - oldx;
|
||||
srect.y += y - oldy;
|
||||
|
||||
drect.x = x;
|
||||
drect.y = y;
|
||||
drect.x = x;
|
||||
drect.y = y;
|
||||
|
||||
//SDL_LockSurface(TheScreen);
|
||||
SDL_BlitSurface(OnlyFogSurface, &srect, TheScreen, &drect);
|
||||
//SDL_UnlockSurface(TheScreen);
|
||||
}
|
||||
//SDL_LockSurface(TheScreen);
|
||||
SDL_BlitSurface(OnlyFogSurface, &srect, TheScreen, &drect);
|
||||
//SDL_UnlockSurface(TheScreen);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
|
@ -596,14 +588,7 @@ static void DrawFogOfWarTile(int sx, int sy, int dx, int dy)
|
|||
|
||||
if (IsMapFieldVisibleTable(sx) || ReplayRevealMap) {
|
||||
if (fogTile && fogTile != blackFogTile) {
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
Map.FogGraphic->DrawFrameClipTrans(fogTile, dx, dy, FogOfWarOpacity);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
AlphaFogG->DrawFrameClip(fogTile, dx, dy);
|
||||
}
|
||||
AlphaFogG->DrawFrameClip(fogTile, dx, dy);
|
||||
}
|
||||
} else {
|
||||
VideoDrawOnlyFog(dx, dy);
|
||||
|
@ -677,70 +662,65 @@ void CMap::InitFogOfWar()
|
|||
|
||||
FogGraphic->Load();
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (!UseOpenGL)
|
||||
#endif
|
||||
{
|
||||
//
|
||||
// Generate Only Fog surface.
|
||||
//
|
||||
OnlyFogSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, PixelTileSize.x, PixelTileSize.y,
|
||||
32, RMASK, GMASK, BMASK, AMASK);
|
||||
//
|
||||
// Generate Only Fog surface.
|
||||
//
|
||||
OnlyFogSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, PixelTileSize.x, PixelTileSize.y,
|
||||
32, RMASK, GMASK, BMASK, AMASK);
|
||||
|
||||
SDL_GetRGB(FogOfWarColorSDL, TheScreen->format, &r, &g, &b);
|
||||
Uint32 color = Video.MapRGBA(OnlyFogSurface->format, r, g, b, FogOfWarOpacity);
|
||||
SDL_GetRGB(FogOfWarColorSDL, TheScreen->format, &r, &g, &b);
|
||||
Uint32 color = Video.MapRGBA(OnlyFogSurface->format, r, g, b, FogOfWarOpacity);
|
||||
|
||||
SDL_FillRect(OnlyFogSurface, NULL, color);
|
||||
//SDL_SetSurfaceAlphaMod(OnlyFogSurface, FogOfWarOpacity);
|
||||
//VideoPaletteListRemove(OnlyFogSurface);
|
||||
SDL_FillRect(OnlyFogSurface, NULL, color);
|
||||
//SDL_SetSurfaceAlphaMod(OnlyFogSurface, FogOfWarOpacity);
|
||||
//VideoPaletteListRemove(OnlyFogSurface);
|
||||
|
||||
//
|
||||
// Generate Alpha Fog surface.
|
||||
//
|
||||
if (FogGraphic->Surface->format->BytesPerPixel == 1) {
|
||||
s = SDL_ConvertSurfaceFormat(FogGraphic->Surface, SDL_PIXELFORMAT_RGB888, 0);
|
||||
SDL_SetSurfaceAlphaMod(s, FogOfWarOpacity);
|
||||
} else {
|
||||
// Copy the top row to a new surface
|
||||
SDL_PixelFormat *f = FogGraphic->Surface->format;
|
||||
s = SDL_CreateRGBSurface(SDL_SWSURFACE, FogGraphic->Surface->w, PixelTileSize.y,
|
||||
f->BitsPerPixel, f->Rmask, f->Gmask, f->Bmask, f->Amask);
|
||||
SDL_LockSurface(s);
|
||||
SDL_LockSurface(FogGraphic->Surface);
|
||||
for (int i = 0; i < s->h; ++i) {
|
||||
memcpy(reinterpret_cast<Uint8 *>(s->pixels) + i * s->pitch,
|
||||
reinterpret_cast<Uint8 *>(FogGraphic->Surface->pixels) + i * FogGraphic->Surface->pitch,
|
||||
FogGraphic->Surface->w * f->BytesPerPixel);
|
||||
}
|
||||
SDL_UnlockSurface(s);
|
||||
SDL_UnlockSurface(FogGraphic->Surface);
|
||||
//
|
||||
// Generate Alpha Fog surface.
|
||||
//
|
||||
if (FogGraphic->Surface->format->BytesPerPixel == 1) {
|
||||
s = SDL_ConvertSurfaceFormat(FogGraphic->Surface, SDL_PIXELFORMAT_RGB888, 0);
|
||||
SDL_SetSurfaceAlphaMod(s, FogOfWarOpacity);
|
||||
} else {
|
||||
// Copy the top row to a new surface
|
||||
SDL_PixelFormat *f = FogGraphic->Surface->format;
|
||||
s = SDL_CreateRGBSurface(SDL_SWSURFACE, FogGraphic->Surface->w, PixelTileSize.y,
|
||||
f->BitsPerPixel, f->Rmask, f->Gmask, f->Bmask, f->Amask);
|
||||
SDL_LockSurface(s);
|
||||
SDL_LockSurface(FogGraphic->Surface);
|
||||
for (int i = 0; i < s->h; ++i) {
|
||||
memcpy(reinterpret_cast<Uint8 *>(s->pixels) + i * s->pitch,
|
||||
reinterpret_cast<Uint8 *>(FogGraphic->Surface->pixels) + i * FogGraphic->Surface->pitch,
|
||||
FogGraphic->Surface->w * f->BytesPerPixel);
|
||||
}
|
||||
SDL_UnlockSurface(s);
|
||||
SDL_UnlockSurface(FogGraphic->Surface);
|
||||
|
||||
// Convert any non-transparent pixels to use FogOfWarOpacity as alpha
|
||||
SDL_LockSurface(s);
|
||||
for (int j = 0; j < s->h; ++j) {
|
||||
for (int i = 0; i < s->w; ++i) {
|
||||
Uint32 c = *reinterpret_cast<Uint32 *>(&reinterpret_cast<Uint8 *>(s->pixels)[i * 4 + j * s->pitch]);
|
||||
Uint8 a;
|
||||
// Convert any non-transparent pixels to use FogOfWarOpacity as alpha
|
||||
SDL_LockSurface(s);
|
||||
for (int j = 0; j < s->h; ++j) {
|
||||
for (int i = 0; i < s->w; ++i) {
|
||||
Uint32 c = *reinterpret_cast<Uint32 *>(&reinterpret_cast<Uint8 *>(s->pixels)[i * 4 + j * s->pitch]);
|
||||
Uint8 a;
|
||||
|
||||
Video.GetRGBA(c, s->format, &r, &g, &b, &a);
|
||||
if (a) {
|
||||
c = Video.MapRGBA(s->format, r, g, b, FogOfWarOpacity);
|
||||
*reinterpret_cast<Uint32 *>(&reinterpret_cast<Uint8 *>(s->pixels)[i * 4 + j * s->pitch]) = c;
|
||||
}
|
||||
Video.GetRGBA(c, s->format, &r, &g, &b, &a);
|
||||
if (a) {
|
||||
c = Video.MapRGBA(s->format, r, g, b, FogOfWarOpacity);
|
||||
*reinterpret_cast<Uint32 *>(&reinterpret_cast<Uint8 *>(s->pixels)[i * 4 + j * s->pitch]) = c;
|
||||
}
|
||||
}
|
||||
SDL_UnlockSurface(s);
|
||||
}
|
||||
AlphaFogG = CGraphic::New("");
|
||||
AlphaFogG->Surface = s;
|
||||
AlphaFogG->Width = PixelTileSize.x;
|
||||
AlphaFogG->Height = PixelTileSize.y;
|
||||
AlphaFogG->GraphicWidth = s->w;
|
||||
AlphaFogG->GraphicHeight = s->h;
|
||||
AlphaFogG->NumFrames = 16;//1;
|
||||
AlphaFogG->GenFramesMap();
|
||||
AlphaFogG->UseDisplayFormat();
|
||||
SDL_UnlockSurface(s);
|
||||
}
|
||||
AlphaFogG = CGraphic::New("");
|
||||
AlphaFogG->Surface = s;
|
||||
AlphaFogG->Width = PixelTileSize.x;
|
||||
AlphaFogG->Height = PixelTileSize.y;
|
||||
AlphaFogG->GraphicWidth = s->w;
|
||||
AlphaFogG->GraphicHeight = s->h;
|
||||
AlphaFogG->NumFrames = 16;//1;
|
||||
AlphaFogG->GenFramesMap();
|
||||
AlphaFogG->UseDisplayFormat();
|
||||
|
||||
VisibleTable.clear();
|
||||
VisibleTable.resize(Info.MapWidth * Info.MapHeight);
|
||||
|
@ -756,18 +736,13 @@ void CMap::CleanFogOfWar()
|
|||
CGraphic::Free(Map.FogGraphic);
|
||||
FogGraphic = NULL;
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (!UseOpenGL)
|
||||
#endif
|
||||
{
|
||||
if (OnlyFogSurface) {
|
||||
VideoPaletteListRemove(OnlyFogSurface);
|
||||
SDL_FreeSurface(OnlyFogSurface);
|
||||
OnlyFogSurface = NULL;
|
||||
}
|
||||
CGraphic::Free(AlphaFogG);
|
||||
AlphaFogG = NULL;
|
||||
if (OnlyFogSurface) {
|
||||
VideoPaletteListRemove(OnlyFogSurface);
|
||||
SDL_FreeSurface(OnlyFogSurface);
|
||||
OnlyFogSurface = NULL;
|
||||
}
|
||||
CGraphic::Free(AlphaFogG);
|
||||
AlphaFogG = NULL;
|
||||
}
|
||||
|
||||
//@}
|
||||
|
|
|
@ -70,15 +70,6 @@
|
|||
SDL_Surface *MinimapSurface; /// generated minimap
|
||||
SDL_Surface *MinimapTerrainSurface; /// generated minimap terrain
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
unsigned char *MinimapSurfaceGL;
|
||||
unsigned char *MinimapTerrainSurfaceGL;
|
||||
|
||||
static GLuint MinimapTexture;
|
||||
static int MinimapTextureWidth;
|
||||
static int MinimapTextureHeight;
|
||||
#endif
|
||||
|
||||
static int *Minimap2MapX; /// fast conversion table
|
||||
static int *Minimap2MapY; /// fast conversion table
|
||||
static int Map2MinimapX[MaxMapWidth]; /// fast conversion table
|
||||
|
@ -105,25 +96,6 @@ int NumMinimapEvents;
|
|||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
/**
|
||||
** Create the minimap texture
|
||||
*/
|
||||
static void CreateMinimapTexture()
|
||||
{
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glGenTextures(1, &MinimapTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, MinimapTexture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, MinimapTextureWidth,
|
||||
MinimapTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
|
||||
MinimapSurfaceGL);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
** Create a mini-map from the tiles of the map.
|
||||
**
|
||||
|
@ -166,47 +138,15 @@ void CMinimap::Create()
|
|||
}
|
||||
|
||||
// Palette updated from UpdateMinimapTerrain()
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
for (MinimapTextureWidth = 1; MinimapTextureWidth < W; MinimapTextureWidth <<= 1) {
|
||||
}
|
||||
for (MinimapTextureHeight = 1; MinimapTextureHeight < H; MinimapTextureHeight <<= 1) {
|
||||
}
|
||||
MinimapTerrainSurfaceGL = new unsigned char[MinimapTextureWidth * MinimapTextureHeight * 4];
|
||||
MinimapSurfaceGL = new unsigned char[MinimapTextureWidth * MinimapTextureHeight * 4];
|
||||
memset(MinimapSurfaceGL, 0, MinimapTextureWidth * MinimapTextureHeight * 4);
|
||||
CreateMinimapTexture();
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
SDL_PixelFormat *f = Map.TileGraphic->Surface->format;
|
||||
MinimapTerrainSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, W, H, f->BitsPerPixel, f->Rmask, f->Gmask, f->Bmask, f->Amask);
|
||||
MinimapSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, W, H, 32, TheScreen->format->Rmask, TheScreen->format->Gmask, TheScreen->format->Bmask, 0);
|
||||
}
|
||||
SDL_PixelFormat *f = Map.TileGraphic->Surface->format;
|
||||
MinimapTerrainSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, W, H, f->BitsPerPixel, f->Rmask, f->Gmask, f->Bmask, f->Amask);
|
||||
MinimapSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, W, H, 32, TheScreen->format->Rmask, TheScreen->format->Gmask, TheScreen->format->Bmask, 0);
|
||||
|
||||
UpdateTerrain();
|
||||
|
||||
NumMinimapEvents = 0;
|
||||
}
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
/**
|
||||
** Free OpenGL minimap
|
||||
*/
|
||||
void CMinimap::FreeOpenGL()
|
||||
{
|
||||
glDeleteTextures(1, &MinimapTexture);
|
||||
}
|
||||
|
||||
/**
|
||||
** Reload OpenGL minimap
|
||||
*/
|
||||
void CMinimap::Reload()
|
||||
{
|
||||
CreateMinimapTexture();
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
** Calculate the tile graphic pixel
|
||||
*/
|
||||
|
@ -233,24 +173,14 @@ void CMinimap::UpdateTerrain()
|
|||
}
|
||||
const int bpp = Map.TileGraphic->Surface->format->BytesPerPixel;
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (!UseOpenGL)
|
||||
#endif
|
||||
{
|
||||
if (bpp == 1) {
|
||||
SDL_SetPaletteColors(MinimapTerrainSurface->format->palette,
|
||||
Map.TileGraphic->Surface->format->palette->colors, 0, 256);
|
||||
}
|
||||
if (bpp == 1) {
|
||||
SDL_SetPaletteColors(MinimapTerrainSurface->format->palette,
|
||||
Map.TileGraphic->Surface->format->palette->colors, 0, 256);
|
||||
}
|
||||
|
||||
const int tilepitch = Map.TileGraphic->Surface->w / PixelTileSize.x;
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (!UseOpenGL)
|
||||
#endif
|
||||
{
|
||||
//SDL_LockSurface(MinimapTerrainSurface);
|
||||
}
|
||||
//SDL_LockSurface(MinimapTerrainSurface);
|
||||
//SDL_LockSurface(Map.TileGraphic->Surface);
|
||||
|
||||
//
|
||||
|
@ -262,49 +192,23 @@ void CMinimap::UpdateTerrain()
|
|||
const int xofs = PixelTileSize.x * (tile % tilepitch);
|
||||
const int yofs = PixelTileSize.y * (tile / tilepitch);
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
Uint32 c;
|
||||
|
||||
if (bpp == 1) {
|
||||
SDL_Color color = Map.TileGraphic->Surface->format->palette->colors[
|
||||
*GetTileGraphicPixel(xofs, yofs, mx, my, scalex, scaley, bpp)];
|
||||
c = Video.MapRGB(0, color.r, color.g, color.b);
|
||||
} else {
|
||||
SDL_PixelFormat *f = Map.TileGraphic->Surface->format;
|
||||
c = *(Uint32 *)GetTileGraphicPixel(xofs, yofs, mx, my, scalex, scaley, bpp);
|
||||
c = Video.MapRGB(0,
|
||||
((c & f->Rmask) >> f->Rshift),
|
||||
((c & f->Gmask) >> f->Gshift),
|
||||
((c & f->Bmask) >> f->Bshift));
|
||||
}
|
||||
*(Uint32 *)&(MinimapTerrainSurfaceGL[(mx + my * MinimapTextureWidth) * 4]) = c;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
if (bpp == 1) {
|
||||
((Uint8 *)MinimapTerrainSurface->pixels)[mx + my * MinimapTerrainSurface->pitch] =
|
||||
*GetTileGraphicPixel(xofs, yofs, mx, my, scalex, scaley, bpp);
|
||||
} else if (bpp == 3) {
|
||||
Uint8 *d = &((Uint8 *)MinimapTerrainSurface->pixels)[mx * bpp + my * MinimapTerrainSurface->pitch];
|
||||
Uint8 *s = GetTileGraphicPixel(xofs, yofs, mx, my, scalex, scaley, bpp);
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
} else {
|
||||
*(Uint32 *)&((Uint8 *)MinimapTerrainSurface->pixels)[mx * bpp + my * MinimapTerrainSurface->pitch] =
|
||||
*(Uint32 *)GetTileGraphicPixel(xofs, yofs, mx, my, scalex, scaley, bpp);
|
||||
}
|
||||
if (bpp == 1) {
|
||||
((Uint8 *)MinimapTerrainSurface->pixels)[mx + my * MinimapTerrainSurface->pitch] =
|
||||
*GetTileGraphicPixel(xofs, yofs, mx, my, scalex, scaley, bpp);
|
||||
} else if (bpp == 3) {
|
||||
Uint8 *d = &((Uint8 *)MinimapTerrainSurface->pixels)[mx * bpp + my * MinimapTerrainSurface->pitch];
|
||||
Uint8 *s = GetTileGraphicPixel(xofs, yofs, mx, my, scalex, scaley, bpp);
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
} else {
|
||||
*(Uint32 *)&((Uint8 *)MinimapTerrainSurface->pixels)[mx * bpp + my * MinimapTerrainSurface->pitch] =
|
||||
*(Uint32 *)GetTileGraphicPixel(xofs, yofs, mx, my, scalex, scaley, bpp);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (!UseOpenGL)
|
||||
#endif
|
||||
{
|
||||
//SDL_UnlockSurface(MinimapTerrainSurface);
|
||||
}
|
||||
//SDL_UnlockSurface(MinimapTerrainSurface);
|
||||
//SDL_UnlockSurface(Map.TileGraphic->Surface);
|
||||
}
|
||||
|
||||
|
@ -315,17 +219,8 @@ void CMinimap::UpdateTerrain()
|
|||
*/
|
||||
void CMinimap::UpdateXY(const Vec2i &pos)
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
if (!MinimapTerrainSurfaceGL) {
|
||||
return;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
if (!MinimapTerrainSurface) {
|
||||
return;
|
||||
}
|
||||
if (!MinimapTerrainSurface) {
|
||||
return;
|
||||
}
|
||||
|
||||
int scalex = MinimapScaleX * SCALE_PRECISION / MINIMAP_FAC;
|
||||
|
@ -343,12 +238,7 @@ void CMinimap::UpdateXY(const Vec2i &pos)
|
|||
//
|
||||
// Pixel 7,6 7,14, 15,6 15,14 are taken for the minimap picture.
|
||||
//
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (!UseOpenGL)
|
||||
#endif
|
||||
{
|
||||
//SDL_LockSurface(MinimapTerrainSurface);
|
||||
}
|
||||
//SDL_LockSurface(MinimapTerrainSurface);
|
||||
//SDL_LockSurface(Map.TileGraphic->Surface);
|
||||
|
||||
const int ty = pos.y * Map.Info.MapWidth;
|
||||
|
@ -380,50 +270,22 @@ void CMinimap::UpdateXY(const Vec2i &pos)
|
|||
const int xofs = PixelTileSize.x * (tile % tilepitch);
|
||||
const int yofs = PixelTileSize.y * (tile / tilepitch);
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
Uint32 c;
|
||||
const int index = mx * bpp + my * MinimapTerrainSurface->pitch;
|
||||
Uint8 *s = GetTileGraphicPixel(xofs, yofs, mx, my, scalex, scaley, bpp);
|
||||
if (bpp == 1) {
|
||||
((Uint8 *)MinimapTerrainSurface->pixels)[index] = *s;
|
||||
} else if (bpp == 3) {
|
||||
Uint8 *d = &((Uint8 *)MinimapTerrainSurface->pixels)[index];
|
||||
|
||||
if (bpp == 1) {
|
||||
const int colorIndex = *GetTileGraphicPixel(xofs, yofs, mx, my, scalex, scaley, bpp);
|
||||
const SDL_Color color = Map.TileGraphic->Surface->format->palette->colors[colorIndex];
|
||||
|
||||
c = Video.MapRGB(0, color.r, color.g, color.b);
|
||||
} else {
|
||||
SDL_PixelFormat *f = Map.TileGraphic->Surface->format;
|
||||
|
||||
c = *(Uint32 *)GetTileGraphicPixel(xofs, yofs, mx, my, scalex, scaley, bpp);
|
||||
c = Video.MapRGB(0,
|
||||
((c & f->Rmask) >> f->Rshift),
|
||||
((c & f->Gmask) >> f->Gshift),
|
||||
((c & f->Bmask) >> f->Bshift));
|
||||
}
|
||||
*(Uint32 *)&(MinimapTerrainSurfaceGL[(mx + my * MinimapTextureWidth) * 4]) = c;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
const int index = mx * bpp + my * MinimapTerrainSurface->pitch;
|
||||
Uint8 *s = GetTileGraphicPixel(xofs, yofs, mx, my, scalex, scaley, bpp);
|
||||
if (bpp == 1) {
|
||||
((Uint8 *)MinimapTerrainSurface->pixels)[index] = *s;
|
||||
} else if (bpp == 3) {
|
||||
Uint8 *d = &((Uint8 *)MinimapTerrainSurface->pixels)[index];
|
||||
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
} else {
|
||||
*(Uint32 *)&((Uint8 *)MinimapTerrainSurface->pixels)[index] = *(Uint32 *)s;
|
||||
}
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
*d++ = *s++;
|
||||
} else {
|
||||
*(Uint32 *)&((Uint8 *)MinimapTerrainSurface->pixels)[index] = *(Uint32 *)s;
|
||||
}
|
||||
}
|
||||
}
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (!UseOpenGL)
|
||||
#endif
|
||||
{
|
||||
//SDL_UnlockSurface(MinimapTerrainSurface);
|
||||
}
|
||||
//SDL_UnlockSurface(MinimapTerrainSurface);
|
||||
//SDL_UnlockSurface(Map.TileGraphic->Surface);
|
||||
}
|
||||
|
||||
|
@ -472,29 +334,17 @@ static void DrawUnitOn(CUnit &unit, int red_phase)
|
|||
h0 = UI.Minimap.H - my;
|
||||
}
|
||||
int bpp = 0;
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (!UseOpenGL)
|
||||
#endif
|
||||
{
|
||||
SDL_Color c;
|
||||
bpp = MinimapSurface->format->BytesPerPixel;
|
||||
SDL_GetRGB(color, TheScreen->format, &c.r, &c.g, &c.b);
|
||||
}
|
||||
SDL_Color c;
|
||||
bpp = MinimapSurface->format->BytesPerPixel;
|
||||
SDL_GetRGB(color, TheScreen->format, &c.r, &c.g, &c.b);
|
||||
while (w-- >= 0) {
|
||||
int h = h0;
|
||||
while (h-- >= 0) {
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
*(Uint32 *)&(MinimapSurfaceGL[((mx + w) + (my + h) * MinimapTextureWidth) * 4]) = color;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
const unsigned int index = (mx + w) * bpp + (my + h) * MinimapSurface->pitch;
|
||||
if (bpp == 2) {
|
||||
*(Uint16 *)&((Uint8 *)MinimapSurface->pixels)[index] = color;
|
||||
} else {
|
||||
*(Uint32 *)&((Uint8 *)MinimapSurface->pixels)[index] = color;
|
||||
}
|
||||
const unsigned int index = (mx + w) * bpp + (my + h) * MinimapSurface->pitch;
|
||||
if (bpp == 2) {
|
||||
*(Uint16 *)&((Uint8 *)MinimapSurface->pixels)[index] = color;
|
||||
} else {
|
||||
*(Uint32 *)&((Uint8 *)MinimapSurface->pixels)[index] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -514,47 +364,21 @@ void CMinimap::Update()
|
|||
|
||||
// Clear Minimap background if not transparent
|
||||
if (!Transparent) {
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
memset(MinimapSurfaceGL, 0, MinimapTextureWidth * MinimapTextureHeight * 4);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
SDL_FillRect(MinimapSurface, NULL, SDL_MapRGB(MinimapSurface->format, 0, 0, 0));
|
||||
}
|
||||
SDL_FillRect(MinimapSurface, NULL, SDL_MapRGB(MinimapSurface->format, 0, 0, 0));
|
||||
}
|
||||
|
||||
int bpp;
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
bpp = 0;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
bpp = MinimapSurface->format->BytesPerPixel;
|
||||
}
|
||||
bpp = MinimapSurface->format->BytesPerPixel;
|
||||
|
||||
//
|
||||
// Draw the terrain
|
||||
//
|
||||
if (WithTerrain) {
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
memcpy(MinimapSurfaceGL, MinimapTerrainSurfaceGL, MinimapTextureWidth * MinimapTextureHeight * 4);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
SDL_BlitSurface(MinimapTerrainSurface, NULL, MinimapSurface, NULL);
|
||||
}
|
||||
SDL_BlitSurface(MinimapTerrainSurface, NULL, MinimapSurface, NULL);
|
||||
}
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (!UseOpenGL)
|
||||
#endif
|
||||
{
|
||||
//SDL_LockSurface(MinimapSurface);
|
||||
//SDL_LockSurface(MinimapTerrainSurface);
|
||||
}
|
||||
//SDL_LockSurface(MinimapSurface);
|
||||
//SDL_LockSurface(MinimapTerrainSurface);
|
||||
|
||||
for (int my = 0; my < H; ++my) {
|
||||
for (int mx = 0; mx < W; ++mx) {
|
||||
|
@ -568,29 +392,17 @@ void CMinimap::Update()
|
|||
}
|
||||
|
||||
if (visiontype == 0 || (visiontype == 1 && ((mx & 1) != (my & 1)))) {
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
*(Uint32 *)&(MinimapSurfaceGL[(mx + my * MinimapTextureWidth) * 4]) = Video.MapRGB(0, 0, 0, 0);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
const int index = mx * bpp + my * MinimapSurface->pitch;
|
||||
if (bpp == 2) {
|
||||
*(Uint16 *)&((Uint8 *)MinimapSurface->pixels)[index] = ColorBlack;
|
||||
} else {
|
||||
*(Uint32 *)&((Uint8 *)MinimapSurface->pixels)[index] = ColorBlack;
|
||||
}
|
||||
const int index = mx * bpp + my * MinimapSurface->pitch;
|
||||
if (bpp == 2) {
|
||||
*(Uint16 *)&((Uint8 *)MinimapSurface->pixels)[index] = ColorBlack;
|
||||
} else {
|
||||
*(Uint32 *)&((Uint8 *)MinimapSurface->pixels)[index] = ColorBlack;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (!UseOpenGL)
|
||||
#endif
|
||||
{
|
||||
//SDL_UnlockSurface(MinimapTerrainSurface);
|
||||
}
|
||||
//SDL_UnlockSurface(MinimapTerrainSurface);
|
||||
|
||||
//
|
||||
// Draw units on map
|
||||
|
@ -601,12 +413,7 @@ void CMinimap::Update()
|
|||
DrawUnitOn(unit, red_phase);
|
||||
}
|
||||
}
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (!UseOpenGL)
|
||||
#endif
|
||||
{
|
||||
//SDL_UnlockSurface(MinimapSurface);
|
||||
}
|
||||
//SDL_UnlockSurface(MinimapSurface);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -633,57 +440,10 @@ static void DrawEvents()
|
|||
*/
|
||||
void CMinimap::Draw() const
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
glBindTexture(GL_TEXTURE_2D, MinimapTexture);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, MinimapTextureWidth, MinimapTextureHeight,
|
||||
GL_RGBA, GL_UNSIGNED_BYTE, MinimapSurfaceGL);
|
||||
|
||||
#ifdef USE_GLES
|
||||
float texCoord[] = {
|
||||
0.0f, 0.0f,
|
||||
(float)W / MinimapTextureWidth, 0.0f,
|
||||
0.0f, (float)H / MinimapTextureHeight,
|
||||
(float)W / MinimapTextureWidth, (float)H / MinimapTextureHeight
|
||||
};
|
||||
|
||||
float vertex[] = {
|
||||
2.0f / (GLfloat)Video.Width *X - 1.0f, -2.0f / (GLfloat)Video.Height *Y + 1.0f,
|
||||
2.0f / (GLfloat)Video.Width *(X + W) - 1.0f, -2.0f / (GLfloat)Video.Height *Y + 1.0f,
|
||||
2.0f / (GLfloat)Video.Width *X - 1.0f, -2.0f / (GLfloat)Video.Height *(Y + H) + 1.0f,
|
||||
2.0f / (GLfloat)Video.Width *(X + W) - 1.0f, -2.0f / (GLfloat)Video.Height *(Y + H) + 1.0f
|
||||
};
|
||||
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, texCoord);
|
||||
glVertexPointer(2, GL_FLOAT, 0, vertex);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
#endif
|
||||
#ifdef USE_OPENGL
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0.0f, 0.0f);
|
||||
glVertex2i(X, Y);
|
||||
glTexCoord2f(0.0f, (float)H / MinimapTextureHeight);
|
||||
glVertex2i(X, Y + H);
|
||||
glTexCoord2f((float)W / MinimapTextureWidth, (float)H / MinimapTextureHeight);
|
||||
glVertex2i(X + W, Y + H);
|
||||
glTexCoord2f((float)W / MinimapTextureWidth, 0.0f);
|
||||
glVertex2i(X + W, Y);
|
||||
glEnd();
|
||||
#endif
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
SDL_Rect drect = {Sint16(X), Sint16(Y), 0, 0};
|
||||
//SDL_LockSurface(TheScreen);
|
||||
SDL_BlitSurface(MinimapSurface, NULL, TheScreen, &drect);
|
||||
//SDL_UnlockSurface(TheScreen);
|
||||
}
|
||||
SDL_Rect drect = {Sint16(X), Sint16(Y), 0, 0};
|
||||
//SDL_LockSurface(TheScreen);
|
||||
SDL_BlitSurface(MinimapSurface, NULL, TheScreen, &drect);
|
||||
//SDL_UnlockSurface(TheScreen);
|
||||
|
||||
DrawEvents();
|
||||
}
|
||||
|
@ -723,26 +483,13 @@ PixelPos CMinimap::TilePosToScreenPos(const Vec2i &tilePos) const
|
|||
*/
|
||||
void CMinimap::Destroy()
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
delete[] MinimapTerrainSurfaceGL;
|
||||
MinimapTerrainSurfaceGL = NULL;
|
||||
if (MinimapSurfaceGL) {
|
||||
glDeleteTextures(1, &MinimapTexture);
|
||||
delete[] MinimapSurfaceGL;
|
||||
MinimapSurfaceGL = NULL;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
VideoPaletteListRemove(MinimapTerrainSurface);
|
||||
SDL_FreeSurface(MinimapTerrainSurface);
|
||||
MinimapTerrainSurface = NULL;
|
||||
if (MinimapSurface) {
|
||||
VideoPaletteListRemove(MinimapSurface);
|
||||
SDL_FreeSurface(MinimapSurface);
|
||||
MinimapSurface = NULL;
|
||||
}
|
||||
VideoPaletteListRemove(MinimapTerrainSurface);
|
||||
SDL_FreeSurface(MinimapTerrainSurface);
|
||||
MinimapTerrainSurface = NULL;
|
||||
if (MinimapSurface) {
|
||||
VideoPaletteListRemove(MinimapSurface);
|
||||
SDL_FreeSurface(MinimapSurface);
|
||||
MinimapSurface = NULL;
|
||||
}
|
||||
delete[] Minimap2MapX;
|
||||
Minimap2MapX = NULL;
|
||||
|
|
|
@ -170,11 +170,7 @@ void UpdateDisplay()
|
|||
{
|
||||
if (GameRunning || Editor.Running == EditorEditing) {
|
||||
// to prevent empty spaces in the UI
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
Video.FillRectangleClip(ColorBlack, 0, 0, Video.ViewportWidth, Video.ViewportHeight);
|
||||
#else
|
||||
Video.FillRectangleClip(ColorBlack, 0, 0, Video.Width, Video.Height);
|
||||
#endif
|
||||
DrawMapArea();
|
||||
DrawMessages();
|
||||
|
||||
|
@ -326,14 +322,6 @@ static int RealVideoSyncSpeed;
|
|||
|
||||
static void DisplayLoop()
|
||||
{
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
/* update only if screen changed */
|
||||
ValidateOpenGLScreen();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* update only if viewmode changed */
|
||||
CheckViewportMode();
|
||||
|
||||
|
|
|
@ -328,21 +328,6 @@ static void PrintHeader()
|
|||
#ifdef USE_THEORA
|
||||
"THEORA "
|
||||
#endif
|
||||
#ifdef USE_FLUIDSYNTH
|
||||
"FLUIDSYNTH "
|
||||
#endif
|
||||
#ifdef USE_MIKMOD
|
||||
"MIKMOD "
|
||||
#endif
|
||||
#ifdef USE_MNG
|
||||
"MNG "
|
||||
#endif
|
||||
#ifdef USE_OPENGL
|
||||
"OPENGL "
|
||||
#endif
|
||||
#ifdef USE_GLES
|
||||
"GLES "
|
||||
#endif
|
||||
#ifdef USE_WIN32
|
||||
"WIN32 "
|
||||
#endif
|
||||
|
@ -360,9 +345,6 @@ static void PrintHeader()
|
|||
#endif
|
||||
#ifdef USE_X11
|
||||
"X11 "
|
||||
#endif
|
||||
#ifdef USE_TOUCHSCREEN
|
||||
"TOUCHSCREEN "
|
||||
#endif
|
||||
"";
|
||||
|
||||
|
@ -463,10 +445,6 @@ static void Usage()
|
|||
"\t-I addr\t\tNetwork address to use\n"
|
||||
"\t-l\t\tDisable command log\n"
|
||||
"\t-N name\t\tName of the player\n"
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
"\t-o\t\tDo not use OpenGL or OpenGL ES 1.1\n"
|
||||
"\t-O\t\tUse OpenGL or OpenGL ES 1.1\n"
|
||||
#endif
|
||||
"\t-p\t\tEnables debug messages printing in console\n"
|
||||
"\t-P port\t\tNetwork port to use\n"
|
||||
"\t-s sleep\tNumber of frames for the AI to sleep before it starts\n"
|
||||
|
@ -474,13 +452,6 @@ static void Usage()
|
|||
"\t-u userpath\tPath where stratagus saves preferences, log and savegame\n"
|
||||
"\t-v mode\t\tVideo mode resolution in format <xres>x<yres>\n"
|
||||
"\t-W\t\tWindowed video mode\n"
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
"\t-x idx\t\tControls fullscreen scaling if your graphics card supports shaders.\n"\
|
||||
"\t \t\tPass a number to select a shader in your shaders directory by index (starting at 0).\n"\
|
||||
"\t \t\tYou can also use Ctrl+Alt+/ to cycle between these scaling algorithms at runtime.\n"
|
||||
"\t \t\tPass -1 to force old-school nearest neighbour scaling without shaders\n"\
|
||||
"\t-Z mode\t\tGame resolution <xres>x<yres> (scaled to -v output resolution with OpenGL).\n"
|
||||
#endif
|
||||
"map is relative to StratagusLibPath=datapath, use ./map for relative to cwd\n",
|
||||
Parameters::Instance.applicationName.c_str());
|
||||
}
|
||||
|
@ -574,21 +545,6 @@ void ParseCommandLine(int argc, char **argv, Parameters ¶meters)
|
|||
case 'N':
|
||||
parameters.LocalPlayerName = optarg;
|
||||
continue;
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
case 'o':
|
||||
ForceUseOpenGL = 1;
|
||||
UseOpenGL = 0;
|
||||
if (ZoomNoResize) {
|
||||
fprintf(stderr, "Error: -Z only works with OpenGL enabled\n");
|
||||
Usage();
|
||||
exit(-1);
|
||||
}
|
||||
continue;
|
||||
case 'O':
|
||||
ForceUseOpenGL = 1;
|
||||
UseOpenGL = 1;
|
||||
continue;
|
||||
#endif
|
||||
case 'P':
|
||||
CNetworkParameter::Instance.localPort = atoi(optarg);
|
||||
continue;
|
||||
|
@ -619,45 +575,14 @@ void ParseCommandLine(int argc, char **argv, Parameters ¶meters)
|
|||
Usage();
|
||||
exit(-1);
|
||||
}
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (!ZoomNoResize) {
|
||||
Video.Height = Video.ViewportHeight;
|
||||
Video.Width = Video.ViewportWidth;
|
||||
}
|
||||
#else
|
||||
{
|
||||
Video.Height = Video.ViewportHeight;
|
||||
Video.Width = Video.ViewportWidth;
|
||||
}
|
||||
#endif
|
||||
Video.Height = Video.ViewportHeight;
|
||||
Video.Width = Video.ViewportWidth;
|
||||
continue;
|
||||
}
|
||||
case 'W':
|
||||
VideoForceFullScreen = 1;
|
||||
Video.FullScreen = 0;
|
||||
continue;
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
case 'x':
|
||||
Video.ShaderIndex = atoi(optarg);
|
||||
if (atoi(optarg) == -1) {
|
||||
GLShaderPipelineSupported = false;
|
||||
}
|
||||
continue;
|
||||
case 'Z':
|
||||
ForceUseOpenGL = 1;
|
||||
UseOpenGL = 1;
|
||||
ZoomNoResize = 1;
|
||||
sep = strchr(optarg, 'x');
|
||||
if (!sep || !*(sep + 1)) {
|
||||
fprintf(stderr, "%s: incorrect format of video mode resolution -- '%s'\n", argv[0], optarg);
|
||||
Usage();
|
||||
exit(-1);
|
||||
}
|
||||
Video.Height = atoi(sep + 1);
|
||||
*sep = 0;
|
||||
Video.Width = atoi(optarg);
|
||||
continue;
|
||||
#endif
|
||||
case -1:
|
||||
break;
|
||||
case '?':
|
||||
|
|
|
@ -729,19 +729,6 @@ static bool CommandKey(int key)
|
|||
case SDLK_KP_6:
|
||||
KeyScrollState |= ScrollRight;
|
||||
break;
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
case SDLK_SLASH:
|
||||
case SDLK_BACKSLASH:
|
||||
if (KeyModifiers & ModifierAlt) {
|
||||
if (GLShaderPipelineSupported) {
|
||||
char shadername[1024] = { '\0' };
|
||||
LoadShaders(key == SDLK_SLASH ? 1 : -1, shadername);
|
||||
SetMessage("%s", shadername);
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
if (HandleCommandKey(key)) {
|
||||
break;
|
||||
|
@ -1273,13 +1260,8 @@ void HandleButtonUp(unsigned button)
|
|||
-- Lowlevel input functions
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef USE_TOUCHSCREEN
|
||||
int DoubleClickDelay = 1000; /// Time to detect double clicks.
|
||||
int HoldClickDelay = 2000; /// Time to detect hold clicks.
|
||||
#else
|
||||
int DoubleClickDelay = 300; /// Time to detect double clicks.
|
||||
int HoldClickDelay = 1000; /// Time to detect hold clicks.
|
||||
#endif
|
||||
|
||||
static enum {
|
||||
InitialMouseState, /// start state
|
||||
|
@ -1371,28 +1353,11 @@ void InputMouseMove(const EventCallback &callbacks,
|
|||
{
|
||||
PixelPos mousePos(x, y);
|
||||
// Don't reset the mouse state unless we really moved
|
||||
#ifdef USE_TOUCHSCREEN
|
||||
const int buff = 32;
|
||||
const PixelDiff diff = LastMousePos - mousePos;
|
||||
|
||||
if (abs(diff.x) > buff || abs(diff.y) > buff) {
|
||||
MouseState = InitialMouseState;
|
||||
LastMouseTicks = ticks;
|
||||
// Reset rectangle select cursor state if we moved by a lot
|
||||
// - rectangle select should be a drag, not a tap
|
||||
if (CursorState == CursorStateRectangle
|
||||
&& (abs(diff.x) > 2 * buff || abs(diff.y) > 2 * buff)) {
|
||||
CursorState = CursorStatePoint;
|
||||
}
|
||||
}
|
||||
LastMousePos = mousePos;
|
||||
#else
|
||||
if (LastMousePos != mousePos) {
|
||||
MouseState = InitialMouseState;
|
||||
LastMouseTicks = ticks;
|
||||
LastMousePos = mousePos;
|
||||
}
|
||||
#endif
|
||||
callbacks.MouseMoved(mousePos);
|
||||
}
|
||||
|
||||
|
|
|
@ -1628,10 +1628,6 @@ static void UISelectStateButtonDown(unsigned)
|
|||
static void UIHandleButtonDown_OnMap(unsigned button)
|
||||
{
|
||||
Assert(UI.MouseViewport);
|
||||
#ifdef USE_TOUCHSCREEN
|
||||
// Detect double left click
|
||||
const bool doubleLeftButton = MouseButtons & (LeftButton << MouseDoubleShift);
|
||||
#endif
|
||||
if ((MouseButtons & LeftButton) && UI.SelectedViewport != UI.MouseViewport) {
|
||||
UI.SelectedViewport = UI.MouseViewport;
|
||||
DebugPrint("selected viewport changed to %ld.\n" _C_
|
||||
|
@ -1640,12 +1636,6 @@ static void UIHandleButtonDown_OnMap(unsigned button)
|
|||
|
||||
// to redraw the cursor immediately (and avoid up to 1 sec delay
|
||||
if (CursorBuilding) {
|
||||
#ifdef USE_TOUCHSCREEN
|
||||
// On touch screen is building started with double left click
|
||||
if (!doubleLeftButton) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
// Possible Selected[0] was removed from map
|
||||
// need to make sure there is a unit to build
|
||||
if (Selected[0] && (MouseButtons & LeftButton)
|
||||
|
@ -1680,11 +1670,7 @@ static void UIHandleButtonDown_OnMap(unsigned button)
|
|||
if (!Selected.empty() && Selected[0]->Player == ThisPlayer && CursorState == CursorStatePoint) {
|
||||
CursorState = CursorStatePieMenu;
|
||||
}
|
||||
#ifdef USE_TOUCHSCREEN
|
||||
} else if (doubleLeftButton) {
|
||||
#else
|
||||
} else if (MouseButtons & RightButton) {
|
||||
#endif
|
||||
if (!GameObserve && !GamePaused && !GameEstablishing && UI.MouseViewport->IsInsideMapArea(CursorScreenPos)) {
|
||||
CUnit *unit;
|
||||
// FIXME: Rethink the complete chaos of coordinates here
|
||||
|
@ -1852,15 +1838,6 @@ void UIHandleButtonDown(unsigned button)
|
|||
return;
|
||||
}
|
||||
|
||||
#ifdef USE_TOUCHSCREEN
|
||||
// If we are moving with stylus/finger,
|
||||
// left button on touch screen devices is still clicked
|
||||
// Ignore handle if left button is long cliked
|
||||
if (longLeftButton) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool OldShowSightRange;
|
||||
static bool OldShowReactionRange;
|
||||
static bool OldShowAttackRange;
|
||||
|
@ -2063,13 +2040,7 @@ void UIHandleButtonUp(unsigned button)
|
|||
num = SelectUnitsInRectangle(pos0, pos1);
|
||||
}
|
||||
}
|
||||
#ifdef USE_TOUCHSCREEN
|
||||
// On touch screen select single unit only when long click is detected
|
||||
// This fix problem with emulating right mouse button as long left click on touch screens
|
||||
} else if (button == 0x1000001) {
|
||||
#else
|
||||
} else {
|
||||
#endif
|
||||
//
|
||||
// Select single unit
|
||||
//
|
||||
|
|
|
@ -202,99 +202,6 @@ static int CclSetDamageMissile(lua_State *l)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int CclSetMaxOpenGLTexture(lua_State *l)
|
||||
{
|
||||
LuaCheckArgs(l, 1);
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (CclInConfigFile) {
|
||||
GLMaxTextureSizeOverride = LuaToNumber(l, 1);
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int CclSetUseTextureCompression(lua_State *l)
|
||||
{
|
||||
LuaCheckArgs(l, 1);
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (CclInConfigFile) {
|
||||
UseGLTextureCompression = LuaToBoolean(l, 1);
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int CclSetUseOpenGL(lua_State *l)
|
||||
{
|
||||
LuaCheckArgs(l, 1);
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (CclInConfigFile) {
|
||||
// May have been set from the command line
|
||||
if (!ForceUseOpenGL) {
|
||||
UseOpenGL = LuaToBoolean(l, 1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int CclGetUseOpenGL(lua_State *l)
|
||||
{
|
||||
LuaCheckArgs(l, 0);
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
lua_pushboolean(l, UseOpenGL);
|
||||
#else
|
||||
lua_pushboolean(l, 0);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int CclSetZoomNoResize(lua_State *l)
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (CclInConfigFile) {
|
||||
// Did the commandline force OpenGL off?
|
||||
if (ForceUseOpenGL && UseOpenGL == 0) {
|
||||
return 0;
|
||||
}
|
||||
// Did the commandline already force ZoomNoResize on?
|
||||
if (!(ForceUseOpenGL && ZoomNoResize)) {
|
||||
const int args = lua_gettop(l);
|
||||
int originalWidth = 640;
|
||||
int originalHeight = 480;
|
||||
if (args == 1) {
|
||||
ZoomNoResize = LuaToBoolean(l, 1);
|
||||
} else if (args == 2) {
|
||||
originalWidth = LuaToNumber(l, 1);
|
||||
originalHeight = LuaToNumber(l, 2);
|
||||
ZoomNoResize = true;
|
||||
} else {
|
||||
LuaError(l, "Valid calls for SetZoSetZoomNoResize are SetZoomNoResize(isEnabled) or SetZoomNoResize(width, height)");
|
||||
}
|
||||
if (ZoomNoResize) {
|
||||
Video.ViewportWidth = Video.Width;
|
||||
Video.ViewportHeight = Video.Height;
|
||||
Video.Width = originalWidth;
|
||||
Video.Height = originalHeight;
|
||||
UseOpenGL = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int CclGetZoomNoResize(lua_State *l)
|
||||
{
|
||||
LuaCheckArgs(l, 0);
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
lua_pushboolean(l, ZoomNoResize);
|
||||
#else
|
||||
lua_pushboolean(l, 0);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
** Set the video resolution.
|
||||
**
|
||||
|
@ -308,15 +215,8 @@ static int CclSetVideoResolution(lua_State *l)
|
|||
if (!Video.ViewportWidth || !Video.ViewportHeight) {
|
||||
Video.ViewportWidth = LuaToNumber(l, 1);
|
||||
Video.ViewportHeight = LuaToNumber(l, 2);
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (!ZoomNoResize) {
|
||||
Video.Height = Video.ViewportHeight;
|
||||
Video.Width = Video.ViewportWidth;
|
||||
}
|
||||
#else
|
||||
Video.Height = Video.ViewportHeight;
|
||||
Video.Width = Video.ViewportWidth;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@ -1277,12 +1177,6 @@ void UserInterfaceCclRegister()
|
|||
lua_register(Lua, "SetClickMissile", CclSetClickMissile);
|
||||
lua_register(Lua, "SetDamageMissile", CclSetDamageMissile);
|
||||
|
||||
lua_register(Lua, "SetMaxOpenGLTexture", CclSetMaxOpenGLTexture);
|
||||
lua_register(Lua, "SetUseTextureCompression", CclSetUseTextureCompression);
|
||||
lua_register(Lua, "SetUseOpenGL", CclSetUseOpenGL);
|
||||
lua_register(Lua, "GetUseOpenGL", CclGetUseOpenGL);
|
||||
lua_register(Lua, "SetZoomNoResize", CclSetZoomNoResize);
|
||||
lua_register(Lua, "GetZoomNoResize", CclGetZoomNoResize);
|
||||
lua_register(Lua, "SetVideoResolution", CclSetVideoResolution);
|
||||
lua_register(Lua, "GetVideoResolution", CclGetVideoResolution);
|
||||
lua_register(Lua, "SetVideoFullScreen", CclSetVideoFullScreen);
|
||||
|
|
|
@ -94,19 +94,12 @@ void initGuichan()
|
|||
{
|
||||
gcn::Graphics *graphics;
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
graphics = new MyOpenGLGraphics();
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
graphics = new gcn::SDLGraphics();
|
||||
graphics = new gcn::SDLGraphics();
|
||||
|
||||
// Set the target for the graphics object to be the screen.
|
||||
// In other words, we will draw to the screen.
|
||||
// Note, any surface will do, it doesn't have to be the screen.
|
||||
((gcn::SDLGraphics *)graphics)->setTarget(TheScreen);
|
||||
}
|
||||
// Set the target for the graphics object to be the screen.
|
||||
// In other words, we will draw to the screen.
|
||||
// Note, any surface will do, it doesn't have to be the screen.
|
||||
((gcn::SDLGraphics *)graphics)->setTarget(TheScreen);
|
||||
|
||||
Input = new gcn::SDLInput();
|
||||
|
||||
|
@ -115,11 +108,7 @@ void initGuichan()
|
|||
Gui->setInput(Input);
|
||||
Gui->setTop(NULL);
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
Gui->setUseDirtyDrawing(!UseOpenGL);
|
||||
#else
|
||||
Gui->setUseDirtyDrawing(1);
|
||||
#endif
|
||||
|
||||
GuichanCallbacks.ButtonPressed = &MenuHandleButtonDown;
|
||||
GuichanCallbacks.ButtonReleased = &MenuHandleButtonUp;
|
||||
|
@ -171,11 +160,7 @@ void handleInput(const SDL_Event *event)
|
|||
void DrawGuichanWidgets()
|
||||
{
|
||||
if (Gui) {
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
Gui->setUseDirtyDrawing(!UseOpenGL && !GameRunning && !Editor.Running);
|
||||
#else
|
||||
Gui->setUseDirtyDrawing(!GameRunning && !Editor.Running);
|
||||
#endif
|
||||
Gui->draw();
|
||||
}
|
||||
}
|
||||
|
@ -218,110 +203,6 @@ LuaActionListener::~LuaActionListener()
|
|||
{
|
||||
}
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- MyOpenGLGraphics
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
void MyOpenGLGraphics::_beginDraw()
|
||||
{
|
||||
gcn::Rectangle area(0, 0, Video.Width, Video.Height);
|
||||
pushClipArea(area);
|
||||
}
|
||||
|
||||
void MyOpenGLGraphics::_endDraw()
|
||||
{
|
||||
popClipArea();
|
||||
}
|
||||
|
||||
void MyOpenGLGraphics::drawImage(const gcn::Image *image, int srcX, int srcY,
|
||||
int dstX, int dstY, int width, int height)
|
||||
{
|
||||
const gcn::ClipRectangle &r = this->getCurrentClipArea();
|
||||
int right = std::min<int>(r.x + r.width - 1, Video.Width - 1);
|
||||
int bottom = std::min<int>(r.y + r.height - 1, Video.Height - 1);
|
||||
|
||||
if (r.x > right || r.y > bottom) {
|
||||
return;
|
||||
}
|
||||
|
||||
PushClipping();
|
||||
SetClipping(r.x, r.y, right, bottom);
|
||||
((CGraphic *)image)->DrawSubClip(srcX, srcY, width, height,
|
||||
dstX + mClipStack.top().xOffset, dstY + mClipStack.top().yOffset);
|
||||
PopClipping();
|
||||
}
|
||||
|
||||
void MyOpenGLGraphics::drawPoint(int x, int y)
|
||||
{
|
||||
gcn::Color c = this->getColor();
|
||||
Video.DrawPixelClip(Video.MapRGBA(0, c.r, c.g, c.b, c.a),
|
||||
x + mClipStack.top().xOffset, y + mClipStack.top().yOffset);
|
||||
}
|
||||
|
||||
void MyOpenGLGraphics::drawLine(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
gcn::Color c = this->getColor();
|
||||
const PixelPos pos1(x1 + mClipStack.top().xOffset, y1 + mClipStack.top().yOffset);
|
||||
const PixelPos pos2(x2 + mClipStack.top().xOffset, y2 + mClipStack.top().yOffset);
|
||||
|
||||
Video.DrawLineClip(Video.MapRGBA(0, c.r, c.g, c.b, c.a), pos1, pos2);
|
||||
}
|
||||
|
||||
void MyOpenGLGraphics::drawRectangle(const gcn::Rectangle &rectangle)
|
||||
{
|
||||
gcn::Color c = this->getColor();
|
||||
if (c.a == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const gcn::ClipRectangle top = mClipStack.top();
|
||||
gcn::Rectangle area = gcn::Rectangle(rectangle.x + top.xOffset,
|
||||
rectangle.y + top.yOffset,
|
||||
rectangle.width, rectangle.height);
|
||||
|
||||
if (!area.intersect(top)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int x1 = std::max<int>(area.x, top.x);
|
||||
int y1 = std::max<int>(area.y, top.y);
|
||||
int x2 = std::min<int>(area.x + area.width, top.x + top.width);
|
||||
int y2 = std::min<int>(area.y + area.height, top.y + top.height);
|
||||
|
||||
Video.DrawTransRectangle(Video.MapRGB(0, c.r, c.g, c.b),
|
||||
x1, y1, x2 - x1, y2 - y1, mColor.a);
|
||||
}
|
||||
|
||||
void MyOpenGLGraphics::fillRectangle(const gcn::Rectangle &rectangle)
|
||||
{
|
||||
const gcn::Color c = this->getColor();
|
||||
|
||||
if (c.a == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const gcn::ClipRectangle top = mClipStack.top();
|
||||
gcn::Rectangle area = gcn::Rectangle(rectangle.x + top.xOffset,
|
||||
rectangle.y + top.yOffset,
|
||||
rectangle.width, rectangle.height);
|
||||
|
||||
if (!area.intersect(top)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int x1 = std::max<int>(area.x, top.x);
|
||||
int y1 = std::max<int>(area.y, top.y);
|
||||
int x2 = std::min<int>(area.x + area.width, top.x + top.width);
|
||||
int y2 = std::min<int>(area.y + area.height, top.y + top.height);
|
||||
|
||||
Video.FillTransRectangle(Video.MapRGB(0, c.r, c.g, c.b),
|
||||
x1, y1, x2 - x1, y2 - y1, c.a);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- ImageButton
|
||||
----------------------------------------------------------------------------*/
|
||||
|
|
|
@ -375,11 +375,6 @@
|
|||
**
|
||||
** Shadow sprite images
|
||||
**
|
||||
** CUnitType::PlayerColorSprite
|
||||
**
|
||||
** Sprite images of the player colors. This image is drawn
|
||||
** over CUnitType::Sprite. Used with OpenGL only.
|
||||
**
|
||||
**
|
||||
*/
|
||||
/**
|
||||
|
|
|
@ -261,12 +261,7 @@ void DrawCursor()
|
|||
}
|
||||
const PixelPos pos = CursorScreenPos - GameCursor->HotPos;
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (!UseOpenGL &&
|
||||
#else
|
||||
if (
|
||||
#endif
|
||||
!GameRunning && !Editor.Running) {
|
||||
if (!GameRunning && !Editor.Running) {
|
||||
if (!HiddenSurface
|
||||
|| HiddenSurface->w != GameCursor->G->getWidth()
|
||||
|| HiddenSurface->h != GameCursor->G->getHeight()) {
|
||||
|
@ -303,12 +298,7 @@ void DrawCursor()
|
|||
*/
|
||||
void HideCursor()
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (!UseOpenGL &&
|
||||
#else
|
||||
if (
|
||||
#endif
|
||||
!GameRunning && !Editor.Running && GameCursor) {
|
||||
if (!GameRunning && !Editor.Running && GameCursor) {
|
||||
const PixelPos pos = CursorScreenPos - GameCursor->HotPos;
|
||||
SDL_Rect dstRect = {Sint16(pos.x), Sint16(pos.y), 0, 0 };
|
||||
//SDL_LockSurface(TheScreen);
|
||||
|
|
|
@ -138,20 +138,13 @@ CFont &GetGameFont()
|
|||
static void VideoDrawChar(const CGraphic &g,
|
||||
int gx, int gy, int w, int h, int x, int y, const CFontColor &fc)
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
g.DrawSub(gx, gy, w, h, x, y);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
SDL_Rect srect = {Sint16(gx), Sint16(gy), Uint16(w), Uint16(h)};
|
||||
SDL_Rect drect = {Sint16(x), Sint16(y), 0, 0};
|
||||
std::vector<SDL_Color> sdlColors(fc.Colors, fc.Colors + MaxFontColors);
|
||||
SDL_SetPaletteColors(g.Surface->format->palette, &sdlColors[0], 0, MaxFontColors);
|
||||
//SDL_LockSurface(TheScreen);
|
||||
SDL_BlitSurface(g.Surface, &srect, TheScreen, &drect);
|
||||
//SDL_UnlockSurface(TheScreen);
|
||||
}
|
||||
SDL_Rect srect = {Sint16(gx), Sint16(gy), Uint16(w), Uint16(h)};
|
||||
SDL_Rect drect = {Sint16(x), Sint16(y), 0, 0};
|
||||
std::vector<SDL_Color> sdlColors(fc.Colors, fc.Colors + MaxFontColors);
|
||||
SDL_SetPaletteColors(g.Surface->format->palette, &sdlColors[0], 0, MaxFontColors);
|
||||
//SDL_LockSurface(TheScreen);
|
||||
SDL_BlitSurface(g.Surface, &srect, TheScreen, &drect);
|
||||
//SDL_UnlockSurface(TheScreen);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -463,21 +456,7 @@ unsigned int CFont::DrawChar(CGraphic &g, int utf8, int x, int y, const CFontCol
|
|||
|
||||
CGraphic *CFont::GetFontColorGraphic(const CFontColor &fontColor) const
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
CGraphic* fontColorG = FontColorGraphics[this][&fontColor];
|
||||
if (!fontColorG) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Could not load font color %s for font %s\n", fontColor.Ident.c_str(), this->Ident.c_str());
|
||||
#endif
|
||||
return this->G;
|
||||
}
|
||||
return fontColorG;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
return this->G;
|
||||
}
|
||||
return this->G;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -833,40 +812,6 @@ void CFont::MeasureWidths()
|
|||
SDL_UnlockSurface(G->Surface);
|
||||
}
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
/**
|
||||
** Make font bitmap.
|
||||
*/
|
||||
void CFont::MakeFontColorTextures() const
|
||||
{
|
||||
if (!FontColorGraphics[this].empty()) {
|
||||
// already loaded
|
||||
return;
|
||||
}
|
||||
const CGraphic &g = *this->G;
|
||||
SDL_Surface *s = g.Surface;
|
||||
|
||||
for (FontColorMap::iterator it = FontColors.begin(); it != FontColors.end(); ++it) {
|
||||
CFontColor *fc = it->second;
|
||||
CGraphic *newg = FontColorGraphics[this][fc] = new CGraphic;
|
||||
|
||||
newg->Width = g.Width;
|
||||
newg->Height = g.Height;
|
||||
newg->NumFrames = g.NumFrames;
|
||||
newg->GraphicWidth = g.GraphicWidth;
|
||||
newg->GraphicHeight = g.GraphicHeight;
|
||||
newg->Surface = g.Surface;
|
||||
|
||||
SDL_LockSurface(s);
|
||||
for (int j = 0; j < MaxFontColors; ++j) {
|
||||
s->format->palette->colors[j] = fc->Colors[j];
|
||||
}
|
||||
SDL_UnlockSurface(s);
|
||||
MakeTexture(newg);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void CFont::Load()
|
||||
{
|
||||
if (this->IsLoaded()) {
|
||||
|
@ -877,12 +822,6 @@ void CFont::Load()
|
|||
//ShowLoadProgress("Fonts %s", this->G->File.c_str());
|
||||
this->G->Load();
|
||||
this->MeasureWidths();
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
this->MakeFontColorTextures();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -910,31 +849,6 @@ void LoadFonts()
|
|||
GameFont = CFont::Get("game");
|
||||
}
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
void CFont::FreeOpenGL()
|
||||
{
|
||||
if (this->G) {
|
||||
for (FontColorGraphicMap::iterator it = FontColorGraphics[this].begin();
|
||||
it != FontColorGraphics[this].end(); ++it) {
|
||||
CGraphic &g = *it->second;
|
||||
glDeleteTextures(g.NumTextures, g.Textures);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Free OpenGL fonts
|
||||
*/
|
||||
void FreeOpenGLFonts()
|
||||
{
|
||||
for (FontMap::iterator it = Fonts.begin(); it != Fonts.end(); ++it) {
|
||||
CFont &font = *it->second;
|
||||
|
||||
font.FreeOpenGL();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void CFont::Reload() const
|
||||
{
|
||||
if (this->G) {
|
||||
|
@ -942,23 +856,15 @@ void CFont::Reload() const
|
|||
for (FontColorGraphicMap::iterator it = fontColorGraphicMap.begin();
|
||||
it != fontColorGraphicMap.end(); ++it) {
|
||||
CGraphic *g = it->second;
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
delete[] g->Textures;
|
||||
#endif
|
||||
delete g;
|
||||
}
|
||||
fontColorGraphicMap.clear();
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
this->MakeFontColorTextures();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
** Reload OpenGL fonts
|
||||
** Reload fonts
|
||||
*/
|
||||
void ReloadFonts()
|
||||
{
|
||||
|
@ -1057,23 +963,6 @@ CFontColor::~CFontColor()
|
|||
|
||||
void CFont::Clean()
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
CFont *font = this;
|
||||
|
||||
if (UseOpenGL) {
|
||||
FontColorGraphicMap &fontColorGraphicMap = FontColorGraphics[font];
|
||||
if (!fontColorGraphicMap.empty()) {
|
||||
for (FontColorGraphicMap::iterator it = fontColorGraphicMap.begin();
|
||||
it != fontColorGraphicMap.end(); ++it) {
|
||||
CGraphic *g = it->second;
|
||||
glDeleteTextures(g->NumTextures, g->Textures);
|
||||
delete[] g->Textures;
|
||||
delete g;
|
||||
}
|
||||
fontColorGraphicMap.clear();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1087,11 +976,6 @@ void CleanFonts()
|
|||
font->Clean();
|
||||
delete font;
|
||||
}
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
FontColorGraphics.clear();
|
||||
}
|
||||
#endif
|
||||
Fonts.clear();
|
||||
|
||||
for (FontColorMap::iterator it = FontColors.begin(); it != FontColors.end(); ++it) {
|
||||
|
|
|
@ -87,18 +87,11 @@ void CGraphic::DrawClip(int x, int y) const
|
|||
*/
|
||||
void CGraphic::DrawSub(int gx, int gy, int w, int h, int x, int y) const
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
DrawTexture(this, Textures, gx, gy, gx + w, gy + h, x, y, 0);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
SDL_Rect srect = {Sint16(gx), Sint16(gy), Uint16(w), Uint16(h)};
|
||||
SDL_Rect drect = {Sint16(x), Sint16(y), 0, 0};
|
||||
//SDL_LockSurface(TheScreen);
|
||||
SDL_BlitSurface(Surface, &srect, TheScreen, &drect);
|
||||
//SDL_UnlockSurface(TheScreen);
|
||||
}
|
||||
SDL_Rect srect = {Sint16(gx), Sint16(gy), Uint16(w), Uint16(h)};
|
||||
SDL_Rect drect = {Sint16(x), Sint16(y), 0, 0};
|
||||
//SDL_LockSurface(TheScreen);
|
||||
SDL_BlitSurface(Surface, &srect, TheScreen, &drect);
|
||||
//SDL_UnlockSurface(TheScreen);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -164,21 +157,11 @@ void CGraphic::DrawSubClip(int gx, int gy, int w, int h, int x, int y) const
|
|||
void CGraphic::DrawSubTrans(int gx, int gy, int w, int h, int x, int y,
|
||||
unsigned char alpha) const
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glColor4ub(255, 255, 255, alpha);
|
||||
DrawSub(gx, gy, w, h, x, y);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
Uint8 oldalpha = 0xff;
|
||||
SDL_GetSurfaceAlphaMod(Surface, &oldalpha);
|
||||
SDL_SetSurfaceAlphaMod(Surface, alpha);
|
||||
DrawSub(gx, gy, w, h, x, y);
|
||||
SDL_SetSurfaceAlphaMod(Surface, oldalpha);
|
||||
}
|
||||
Uint8 oldalpha = 0xff;
|
||||
SDL_GetSurfaceAlphaMod(Surface, &oldalpha);
|
||||
SDL_SetSurfaceAlphaMod(Surface, alpha);
|
||||
DrawSub(gx, gy, w, h, x, y);
|
||||
SDL_SetSurfaceAlphaMod(Surface, oldalpha);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -210,37 +193,10 @@ void CGraphic::DrawSubClipTrans(int gx, int gy, int w, int h, int x, int y,
|
|||
*/
|
||||
void CGraphic::DrawFrame(unsigned frame, int x, int y) const
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
DrawTexture(this, Textures, frame_map[frame].x, frame_map[frame].y,
|
||||
frame_map[frame].x + Width, frame_map[frame].y + Height, x, y, 0);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
DrawSub(frame_map[frame].x, frame_map[frame].y,
|
||||
Width, Height, x, y);
|
||||
}
|
||||
DrawSub(frame_map[frame].x, frame_map[frame].y,
|
||||
Width, Height, x, y);
|
||||
}
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
void CGraphic::DoDrawFrameClip(GLuint *textures,
|
||||
unsigned frame, int x, int y) const
|
||||
{
|
||||
int ox;
|
||||
int oy;
|
||||
int skip;
|
||||
int w = Width;
|
||||
int h = Height;
|
||||
|
||||
CLIP_RECTANGLE_OFS(x, y, w, h, ox, oy, skip);
|
||||
UNUSED(skip);
|
||||
DrawTexture(this, textures, frame_map[frame].x + ox,
|
||||
frame_map[frame].y + oy,
|
||||
frame_map[frame].x + ox + w,
|
||||
frame_map[frame].y + oy + h, x, y, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
** Draw graphic object clipped.
|
||||
**
|
||||
|
@ -250,47 +206,20 @@ void CGraphic::DoDrawFrameClip(GLuint *textures,
|
|||
*/
|
||||
void CGraphic::DrawFrameClip(unsigned frame, int x, int y) const
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
DoDrawFrameClip(Textures, frame, x, y);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
DrawSubClip(frame_map[frame].x, frame_map[frame].y,
|
||||
Width, Height, x, y);
|
||||
}
|
||||
DrawSubClip(frame_map[frame].x, frame_map[frame].y,
|
||||
Width, Height, x, y);
|
||||
}
|
||||
|
||||
void CGraphic::DrawFrameTrans(unsigned frame, int x, int y, int alpha) const
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glColor4ub(255, 255, 255, alpha);
|
||||
DrawFrame(frame, x, y);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
DrawSubTrans(frame_map[frame].x, frame_map[frame].y,
|
||||
Width, Height, x, y, alpha);
|
||||
}
|
||||
DrawSubTrans(frame_map[frame].x, frame_map[frame].y,
|
||||
Width, Height, x, y, alpha);
|
||||
}
|
||||
|
||||
void CGraphic::DrawFrameClipTrans(unsigned frame, int x, int y, int alpha) const
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glColor4ub(255, 255, 255, alpha);
|
||||
DrawFrameClip(frame, x, y);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
DrawSubClipTrans(frame_map[frame].x, frame_map[frame].y,
|
||||
Width, Height, x, y, alpha);
|
||||
}
|
||||
DrawSubClipTrans(frame_map[frame].x, frame_map[frame].y,
|
||||
Width, Height, x, y, alpha);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -304,18 +233,8 @@ void CGraphic::DrawFrameClipTrans(unsigned frame, int x, int y, int alpha) const
|
|||
void CPlayerColorGraphic::DrawPlayerColorFrameClip(int player, unsigned frame,
|
||||
int x, int y)
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
if (!PlayerColorTextures[player]) {
|
||||
MakePlayerColorTexture(this, player);
|
||||
}
|
||||
DoDrawFrameClip(PlayerColorTextures[player], frame, x, y);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
GraphicPlayerPixels(Players[player], *this);
|
||||
DrawFrameClip(frame, x, y);
|
||||
}
|
||||
GraphicPlayerPixels(Players[player], *this);
|
||||
DrawFrameClip(frame, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -327,49 +246,14 @@ void CPlayerColorGraphic::DrawPlayerColorFrameClip(int player, unsigned frame,
|
|||
*/
|
||||
void CGraphic::DrawFrameX(unsigned frame, int x, int y) const
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
DrawTexture(this, Textures, frame_map[frame].x, frame_map[frame].y,
|
||||
frame_map[frame].x + Width, frame_map[frame].y + Height, x, y, 1);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
SDL_Rect srect = {frameFlip_map[frame].x, frameFlip_map[frame].y, Uint16(Width), Uint16(Height)};
|
||||
SDL_Rect drect = {Sint16(x), Sint16(y), 0, 0};
|
||||
SDL_Rect srect = {frameFlip_map[frame].x, frameFlip_map[frame].y, Uint16(Width), Uint16(Height)};
|
||||
SDL_Rect drect = {Sint16(x), Sint16(y), 0, 0};
|
||||
|
||||
//SDL_LockSurface(TheScreen);
|
||||
SDL_BlitSurface(SurfaceFlip, &srect, TheScreen, &drect);
|
||||
//SDL_UnlockSurface(TheScreen);
|
||||
}
|
||||
//SDL_LockSurface(TheScreen);
|
||||
SDL_BlitSurface(SurfaceFlip, &srect, TheScreen, &drect);
|
||||
//SDL_UnlockSurface(TheScreen);
|
||||
}
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
void CGraphic::DoDrawFrameClipX(GLuint *textures, unsigned frame,
|
||||
int x, int y) const
|
||||
{
|
||||
int ox;
|
||||
int oy;
|
||||
int skip;
|
||||
int w = Width;
|
||||
int h = Height;
|
||||
CLIP_RECTANGLE_OFS(x, y, w, h, ox, oy, skip);
|
||||
UNUSED(skip);
|
||||
|
||||
if (w < Width) {
|
||||
if (ox == 0) {
|
||||
ox = Width - w;
|
||||
} else {
|
||||
ox = 0;
|
||||
}
|
||||
}
|
||||
|
||||
DrawTexture(this, textures, frame_map[frame].x + ox,
|
||||
frame_map[frame].y + oy,
|
||||
frame_map[frame].x + ox + w,
|
||||
frame_map[frame].y + oy + h, x, y, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
** Draw graphic object clipped and flipped in X direction.
|
||||
**
|
||||
|
@ -379,105 +263,56 @@ void CGraphic::DoDrawFrameClipX(GLuint *textures, unsigned frame,
|
|||
*/
|
||||
void CGraphic::DrawFrameClipX(unsigned frame, int x, int y) const
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
DoDrawFrameClipX(Textures, frame, x, y);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
SDL_Rect srect = {frameFlip_map[frame].x, frameFlip_map[frame].y, Uint16(Width), Uint16(Height)};
|
||||
SDL_Rect srect = {frameFlip_map[frame].x, frameFlip_map[frame].y, Uint16(Width), Uint16(Height)};
|
||||
|
||||
const int oldx = x;
|
||||
const int oldy = y;
|
||||
CLIP_RECTANGLE(x, y, srect.w, srect.h);
|
||||
#if 1
|
||||
if (File=="graphics/human/units/elven_archer.png" && SurfaceFlip->format->BytesPerPixel == 1)
|
||||
{
|
||||
//FILE *file = fopen("archer-test.data", "w+");
|
||||
FILE *file = fopen("archer-palete-flip-draw.data", "w+");
|
||||
if (file) {
|
||||
//fwrite(s->pixels, 1, s->pitch*s->h, file);
|
||||
//fwrite(s->format->palette->colors, 1, 3 * s->format->palette->ncolors, file);
|
||||
for (int i = 0; i < SurfaceFlip->format->palette->ncolors; i++)
|
||||
fwrite(&SurfaceFlip->format->palette->colors[i], 1, 4, file);
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
srect.x += x - oldx;
|
||||
srect.y += y - oldy;
|
||||
const int oldx = x;
|
||||
const int oldy = y;
|
||||
CLIP_RECTANGLE(x, y, srect.w, srect.h);
|
||||
srect.x += x - oldx;
|
||||
srect.y += y - oldy;
|
||||
|
||||
SDL_Rect drect = {Sint16(x), Sint16(y), 0, 0};
|
||||
SDL_Rect drect = {Sint16(x), Sint16(y), 0, 0};
|
||||
|
||||
int ret;
|
||||
//SDL_LockSurface(TheScreen);
|
||||
//SDL_SetSurfaceAlphaMod(SurfaceFlip, 0xFF);
|
||||
ret = SDL_BlitSurface(SurfaceFlip, &srect, TheScreen, &drect);
|
||||
//SDL_UnlockSurface(TheScreen);
|
||||
#if 1
|
||||
if (File=="graphics/human/units/elven_archer.png" && SurfaceFlip->format->BytesPerPixel == 1)
|
||||
{
|
||||
fprintf(stderr, "drawing flipped archer, srect %d, %d, %dx%d on %d, %d\n", srect.x+x-oldx, srect.y, srect.w, srect.h, drect.x, drect.y);
|
||||
fprintf(stderr, "format %x\n", SurfaceFlip->format->format);
|
||||
if (ret) fprintf(stderr, "flip: %s\n", SDL_GetError());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
int ret;
|
||||
//SDL_LockSurface(TheScreen);
|
||||
//SDL_SetSurfaceAlphaMod(SurfaceFlip, 0xFF);
|
||||
ret = SDL_BlitSurface(SurfaceFlip, &srect, TheScreen, &drect);
|
||||
//SDL_UnlockSurface(TheScreen);
|
||||
}
|
||||
|
||||
void CGraphic::DrawFrameTransX(unsigned frame, int x, int y, int alpha) const
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glColor4ub(255, 255, 255, alpha);
|
||||
DrawFrameX(frame, x, y);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
SDL_Rect srect = {frameFlip_map[frame].x, frameFlip_map[frame].y, Uint16(Width), Uint16(Height)};
|
||||
SDL_Rect drect = {Sint16(x), Sint16(y), 0, 0};
|
||||
Uint8 oldalpha = 0xff;
|
||||
SDL_GetSurfaceAlphaMod(SurfaceFlip, &oldalpha);
|
||||
SDL_Rect srect = {frameFlip_map[frame].x, frameFlip_map[frame].y, Uint16(Width), Uint16(Height)};
|
||||
SDL_Rect drect = {Sint16(x), Sint16(y), 0, 0};
|
||||
Uint8 oldalpha = 0xff;
|
||||
SDL_GetSurfaceAlphaMod(SurfaceFlip, &oldalpha);
|
||||
|
||||
SDL_SetSurfaceAlphaMod(SurfaceFlip, alpha);
|
||||
//SDL_LockSurface(TheScreen);
|
||||
SDL_BlitSurface(SurfaceFlip, &srect, TheScreen, &drect);
|
||||
//SDL_UnlockSurface(TheScreen);
|
||||
SDL_SetSurfaceAlphaMod(SurfaceFlip, oldalpha);
|
||||
}
|
||||
SDL_SetSurfaceAlphaMod(SurfaceFlip, alpha);
|
||||
//SDL_LockSurface(TheScreen);
|
||||
SDL_BlitSurface(SurfaceFlip, &srect, TheScreen, &drect);
|
||||
//SDL_UnlockSurface(TheScreen);
|
||||
SDL_SetSurfaceAlphaMod(SurfaceFlip, oldalpha);
|
||||
}
|
||||
|
||||
void CGraphic::DrawFrameClipTransX(unsigned frame, int x, int y, int alpha) const
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glColor4ub(255, 255, 255, alpha);
|
||||
DrawFrameClipX(frame, x, y);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
SDL_Rect srect = {frameFlip_map[frame].x, frameFlip_map[frame].y, Uint16(Width), Uint16(Height)};
|
||||
SDL_Rect srect = {frameFlip_map[frame].x, frameFlip_map[frame].y, Uint16(Width), Uint16(Height)};
|
||||
|
||||
int oldx = x;
|
||||
int oldy = y;
|
||||
CLIP_RECTANGLE(x, y, srect.w, srect.h);
|
||||
srect.x += x - oldx;
|
||||
srect.y += y - oldy;
|
||||
int oldx = x;
|
||||
int oldy = y;
|
||||
CLIP_RECTANGLE(x, y, srect.w, srect.h);
|
||||
srect.x += x - oldx;
|
||||
srect.y += y - oldy;
|
||||
|
||||
SDL_Rect drect = {Sint16(x), Sint16(y), 0, 0};
|
||||
Uint8 oldalpha = 0xff;
|
||||
SDL_GetSurfaceAlphaMod(SurfaceFlip, &oldalpha);
|
||||
SDL_Rect drect = {Sint16(x), Sint16(y), 0, 0};
|
||||
Uint8 oldalpha = 0xff;
|
||||
SDL_GetSurfaceAlphaMod(SurfaceFlip, &oldalpha);
|
||||
|
||||
SDL_SetSurfaceAlphaMod(SurfaceFlip, alpha);
|
||||
//SDL_LockSurface(TheScreen);
|
||||
SDL_BlitSurface(SurfaceFlip, &srect, TheScreen, &drect);
|
||||
//SDL_UnlockSurface(TheScreen);
|
||||
SDL_SetSurfaceAlphaMod(SurfaceFlip, oldalpha);
|
||||
}
|
||||
SDL_SetSurfaceAlphaMod(SurfaceFlip, alpha);
|
||||
//SDL_LockSurface(TheScreen);
|
||||
SDL_BlitSurface(SurfaceFlip, &srect, TheScreen, &drect);
|
||||
//SDL_UnlockSurface(TheScreen);
|
||||
SDL_SetSurfaceAlphaMod(SurfaceFlip, oldalpha);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -491,18 +326,8 @@ void CGraphic::DrawFrameClipTransX(unsigned frame, int x, int y, int alpha) cons
|
|||
void CPlayerColorGraphic::DrawPlayerColorFrameClipX(int player, unsigned frame,
|
||||
int x, int y)
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
if (!PlayerColorTextures[player]) {
|
||||
MakePlayerColorTexture(this, player);
|
||||
}
|
||||
DoDrawFrameClipX(PlayerColorTextures[player], frame, x, y);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
GraphicPlayerPixels(Players[player], *this);
|
||||
DrawFrameClipX(frame, x, y);
|
||||
}
|
||||
GraphicPlayerPixels(Players[player], *this);
|
||||
DrawFrameClipX(frame, x, y);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
|
@ -699,14 +524,7 @@ CPlayerColorGraphic *CPlayerColorGraphic::ForceNew(const std::string &file, int
|
|||
void CGraphic::GenFramesMap()
|
||||
{
|
||||
Assert(NumFrames != 0);
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
Assert(GraphicWidth != 0);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
Assert(Surface != NULL);
|
||||
}
|
||||
Assert(Surface != NULL);
|
||||
Assert(Width != 0);
|
||||
Assert(Height != 0);
|
||||
|
||||
|
@ -715,16 +533,8 @@ void CGraphic::GenFramesMap()
|
|||
frame_map = new frame_pos_t[NumFrames];
|
||||
|
||||
for (int frame = 0; frame < NumFrames; ++frame) {
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
frame_map[frame].x = (frame % (GraphicWidth / Width)) * Width;
|
||||
frame_map[frame].y = (frame / (GraphicWidth / Width)) * Height;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
frame_map[frame].x = (frame % (Surface->w / Width)) * Width;
|
||||
frame_map[frame].y = (frame / (Surface->w / Width)) * Height;
|
||||
}
|
||||
frame_map[frame].x = (frame % (Surface->w / Width)) * Width;
|
||||
frame_map[frame].y = (frame / (Surface->w / Width)) * Height;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -810,12 +620,6 @@ void CGraphic::Load(bool grayscale)
|
|||
ApplyGrayScale(Surface, Width, Height);
|
||||
}
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
MakeTexture(this);
|
||||
Graphics.push_back(this);
|
||||
}
|
||||
#endif
|
||||
GenFramesMap();
|
||||
}
|
||||
|
||||
|
@ -857,39 +661,13 @@ void CGraphic::Free(CGraphic *g)
|
|||
|
||||
--g->Refs;
|
||||
if (!g->Refs) {
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
// No more uses of this graphic
|
||||
if (UseOpenGL) {
|
||||
if (g->Textures) {
|
||||
glDeleteTextures(g->NumTextures, g->Textures);
|
||||
delete[] g->Textures;
|
||||
g->DeleteColorCyclingTextures();
|
||||
}
|
||||
CPlayerColorGraphic *cg = dynamic_cast<CPlayerColorGraphic *>(g);
|
||||
if (cg) {
|
||||
for (int i = 0; i < PlayerMax; ++i) {
|
||||
if (cg->PlayerColorTextures[i]) {
|
||||
glDeleteTextures(cg->NumTextures, cg->PlayerColorTextures[i]);
|
||||
delete[] cg->PlayerColorTextures[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
Graphics.remove(g);
|
||||
}
|
||||
#endif
|
||||
|
||||
FreeSurface(&g->Surface);
|
||||
delete[] g->frame_map;
|
||||
g->frame_map = NULL;
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (!UseOpenGL)
|
||||
#endif
|
||||
{
|
||||
FreeSurface(&g->SurfaceFlip);
|
||||
delete[] g->frameFlip_map;
|
||||
g->frameFlip_map = NULL;
|
||||
}
|
||||
FreeSurface(&g->SurfaceFlip);
|
||||
delete[] g->frameFlip_map;
|
||||
g->frameFlip_map = NULL;
|
||||
|
||||
if (!g->HashFile.empty()) {
|
||||
GraphicHash.erase(g->HashFile);
|
||||
|
@ -898,69 +676,11 @@ void CGraphic::Free(CGraphic *g)
|
|||
}
|
||||
}
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
|
||||
/**
|
||||
** Free OpenGL graphics
|
||||
*/
|
||||
void FreeOpenGLGraphics()
|
||||
{
|
||||
std::list<CGraphic *>::iterator i;
|
||||
for (i = Graphics.begin(); i != Graphics.end(); ++i) {
|
||||
if ((*i)->Textures) {
|
||||
glDeleteTextures((*i)->NumTextures, (*i)->Textures);
|
||||
}
|
||||
CPlayerColorGraphic *cg = dynamic_cast<CPlayerColorGraphic *>(*i);
|
||||
if (cg) {
|
||||
for (int j = 0; j < PlayerMax; ++j) {
|
||||
if (cg->PlayerColorTextures[j]) {
|
||||
glDeleteTextures(cg->NumTextures, cg->PlayerColorTextures[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Reload OpenGL graphics
|
||||
*/
|
||||
void ReloadGraphics()
|
||||
{
|
||||
std::list<CGraphic *>::iterator i;
|
||||
for (i = Graphics.begin(); i != Graphics.end(); ++i) {
|
||||
if ((*i)->Textures) {
|
||||
delete[](*i)->Textures;
|
||||
(*i)->Textures = NULL;
|
||||
MakeTexture(*i);
|
||||
if ((*i)->DeleteColorCyclingTextures()) {
|
||||
MakeColorCyclingTextures((*i), (*i)->NumColorCycles);
|
||||
}
|
||||
}
|
||||
CPlayerColorGraphic *cg = dynamic_cast<CPlayerColorGraphic *>(*i);
|
||||
if (cg) {
|
||||
for (int j = 0; j < PlayerMax; ++j) {
|
||||
if (cg->PlayerColorTextures[j]) {
|
||||
delete[] cg->PlayerColorTextures[j];
|
||||
cg->PlayerColorTextures[j] = NULL;
|
||||
MakePlayerColorTexture(cg, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
** Flip graphic and store in graphic->SurfaceFlip
|
||||
*/
|
||||
void CGraphic::Flip()
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (SurfaceFlip) {
|
||||
return;
|
||||
}
|
||||
|
@ -1077,10 +797,6 @@ void CGraphic::Flip()
|
|||
*/
|
||||
void CGraphic::UseDisplayFormat()
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) { return; }
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
SDL_Surface *s = Surface;
|
||||
|
||||
|
@ -1106,257 +822,6 @@ void CGraphic::UseDisplayFormat()
|
|||
|
||||
}
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
|
||||
/**
|
||||
** Find the next power of 2 >= x
|
||||
*/
|
||||
static int PowerOf2(int x)
|
||||
{
|
||||
int i;
|
||||
for (i = 1; i < x; i <<= 1) ;
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
** Make an OpenGL texture or textures out of a graphic object.
|
||||
**
|
||||
** @param g The graphic object.
|
||||
** @param texture Texture.
|
||||
** @param colors Unit colors.
|
||||
** @param ow Offset width.
|
||||
** @param oh Offset height.
|
||||
*/
|
||||
static void MakeTextures2(CGraphic *g, GLuint texture, CUnitColors *colors,
|
||||
int ow, int oh)
|
||||
{
|
||||
Uint32 ckey;
|
||||
int useckey = !SDL_GetColorKey(g->Surface, &ckey);
|
||||
SDL_PixelFormat *f = g->Surface->format;
|
||||
int bpp = f->BytesPerPixel;
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
int maxw = std::min<int>(g->GraphicWidth - ow, GLMaxTextureSize);
|
||||
int maxh = std::min<int>(g->GraphicHeight - oh, GLMaxTextureSize);
|
||||
int w = PowerOf2(maxw);
|
||||
int h = PowerOf2(maxh);
|
||||
unsigned char *tex = new unsigned char[w * h * 4];
|
||||
memset(tex, 0, w * h * 4);
|
||||
unsigned char alpha;
|
||||
if (!!SDL_GetSurfaceAlphaMod(g->Surface, &alpha) {
|
||||
alpha = 0xff;
|
||||
}
|
||||
|
||||
SDL_LockSurface(g->Surface);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
|
||||
unsigned char *tp;
|
||||
const unsigned char *sp;
|
||||
Uint32 b;
|
||||
Uint32 c;
|
||||
Uint32 pc;
|
||||
|
||||
for (int i = 0; i < maxh; ++i) {
|
||||
sp = (const unsigned char *)g->Surface->pixels + ow * bpp +
|
||||
(oh + i) * g->Surface->pitch;
|
||||
tp = tex + i * w * 4;
|
||||
for (int j = 0; j < maxw; ++j) {
|
||||
if (bpp == 1) {
|
||||
if (useckey && *sp == ckey) {
|
||||
tp[3] = 0;
|
||||
} else {
|
||||
SDL_Color p = f->palette->colors[*sp];
|
||||
tp[0] = p.r;
|
||||
tp[1] = p.g;
|
||||
tp[2] = p.b;
|
||||
tp[3] = alpha;
|
||||
}
|
||||
if (colors) {
|
||||
for (int z = 0; z < PlayerColorIndexCount; ++z) {
|
||||
if (*sp == PlayerColorIndexStart + z) {
|
||||
SDL_Color p = colors->Colors[z];
|
||||
tp[0] = p.r;
|
||||
tp[1] = p.g;
|
||||
tp[2] = p.b;
|
||||
tp[3] = 0xff;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
++sp;
|
||||
} else {
|
||||
if (bpp == 4) {
|
||||
c = *(Uint32 *)sp;
|
||||
} else {
|
||||
c = (sp[f->Rshift >> 3] << f->Rshift) |
|
||||
(sp[f->Gshift >> 3] << f->Gshift) |
|
||||
(sp[f->Bshift >> 3] << f->Bshift);
|
||||
c |= ((alpha | (alpha << 8) | (alpha << 16) | (alpha << 24)) ^
|
||||
(f->Rmask | f->Gmask | f->Bmask));
|
||||
}
|
||||
*(Uint32 *)tp = c;
|
||||
if (colors) {
|
||||
b = (c & f->Bmask) >> f->Bshift;
|
||||
if (b && ((c & f->Rmask) >> f->Rshift) == 0 &&
|
||||
((c & f->Gmask) >> f->Gshift) == b) {
|
||||
pc = ((colors->Colors[0].R * b / 255) << f->Rshift) |
|
||||
((colors->Colors[0].G * b / 255) << f->Gshift) |
|
||||
((colors->Colors[0].B * b / 255) << f->Bshift);
|
||||
if (bpp == 4) {
|
||||
pc |= (c & f->Amask);
|
||||
} else {
|
||||
pc |= (0xFFFFFFFF ^ (f->Rmask | f->Gmask | f->Bmask));
|
||||
}
|
||||
*(Uint32 *)tp = pc;
|
||||
}
|
||||
}
|
||||
sp += bpp;
|
||||
}
|
||||
tp += 4;
|
||||
}
|
||||
}
|
||||
|
||||
GLint internalformat = GL_RGBA;
|
||||
#ifdef USE_OPENGL
|
||||
if (GLTextureCompressionSupported && UseGLTextureCompression) {
|
||||
internalformat = GL_COMPRESSED_RGBA;
|
||||
}
|
||||
#endif
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalformat, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex);
|
||||
|
||||
#ifdef DEBUG
|
||||
int x;
|
||||
if ((x = glGetError())) {
|
||||
DebugPrint("glTexImage2D(%x)\n" _C_ x);
|
||||
}
|
||||
#endif
|
||||
SDL_UnlockSurface(g->Surface);
|
||||
delete[] tex;
|
||||
}
|
||||
|
||||
/**
|
||||
** Make an OpenGL texture or textures out of a graphic object.
|
||||
**
|
||||
** @param g The graphic object.
|
||||
** @param player Player number.
|
||||
** @param colors Unit colors.
|
||||
*/
|
||||
static void MakeTextures(CGraphic *g, int player, CUnitColors *colors)
|
||||
{
|
||||
int tw = (g->GraphicWidth - 1) / GLMaxTextureSize + 1;
|
||||
const int th = (g->GraphicHeight - 1) / GLMaxTextureSize + 1;
|
||||
|
||||
int w = g->GraphicWidth % GLMaxTextureSize;
|
||||
if (w == 0) {
|
||||
w = GLMaxTextureSize;
|
||||
}
|
||||
g->TextureWidth = (GLfloat)w / PowerOf2(w);
|
||||
|
||||
int h = g->GraphicHeight % GLMaxTextureSize;
|
||||
if (h == 0) {
|
||||
h = GLMaxTextureSize;
|
||||
}
|
||||
g->TextureHeight = (GLfloat)h / PowerOf2(h);
|
||||
|
||||
g->NumTextures = tw * th;
|
||||
|
||||
CPlayerColorGraphic *cg = dynamic_cast<CPlayerColorGraphic *>(g);
|
||||
GLuint *textures;
|
||||
if (!colors || !cg) {
|
||||
textures = g->Textures = new GLuint[g->NumTextures];
|
||||
glGenTextures(g->NumTextures, g->Textures);
|
||||
} else {
|
||||
textures = cg->PlayerColorTextures[player] = new GLuint[cg->NumTextures];
|
||||
glGenTextures(cg->NumTextures, cg->PlayerColorTextures[player]);
|
||||
}
|
||||
|
||||
for (int j = 0; j < th; ++j) {
|
||||
for (int i = 0; i < tw; ++i) {
|
||||
MakeTextures2(g, textures[j * tw + i], colors, GLMaxTextureSize * i, GLMaxTextureSize * j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Make an OpenGL texture or textures out of a graphic object.
|
||||
**
|
||||
** @param g The graphic object.
|
||||
*/
|
||||
void MakeTexture(CGraphic *g)
|
||||
{
|
||||
if (g->Textures) {
|
||||
return;
|
||||
}
|
||||
|
||||
MakeTextures(g, 0, NULL);
|
||||
}
|
||||
|
||||
void LazilyMakeColorCyclingTextures(CGraphic *g, std::vector<ColorIndexRange> ranges)
|
||||
{
|
||||
if (g->ColorCyclingTextures) {
|
||||
return;
|
||||
}
|
||||
// Note: below we just use the longest range for cycling.
|
||||
// Absolutely correct would be the lowest common multiple,
|
||||
// but it's harder to calculate and we run this lazily and don't
|
||||
// want the load.
|
||||
unsigned int count = 0;
|
||||
for (std::vector<ColorIndexRange>::const_iterator it = ranges.begin(); it != ranges.end(); ++it) {
|
||||
const ColorIndexRange &range = *it;
|
||||
count = std::max(range.end - range.begin, count);
|
||||
}
|
||||
count++; // make room for the default texture at the end of the cycle
|
||||
MakeColorCyclingTextures(g, count);
|
||||
}
|
||||
|
||||
void MakeColorCyclingTextures(CGraphic *g, int count)
|
||||
{
|
||||
if (g->ColorCyclingTextures) {
|
||||
return;
|
||||
}
|
||||
MakeTexture(g); // ensure that we are initialized
|
||||
|
||||
int tw = (g->GraphicWidth - 1) / GLMaxTextureSize + 1;
|
||||
const int th = (g->GraphicHeight - 1) / GLMaxTextureSize + 1;
|
||||
|
||||
GLuint **textures;
|
||||
g->NumColorCycles = count;
|
||||
textures = g->ColorCyclingTextures = new GLuint*[count];
|
||||
|
||||
for (int c = 0; c < count; c++) {
|
||||
for (int j = 0; j < th; ++j) {
|
||||
for (int i = 0; i < tw; ++i) {
|
||||
textures[c] = new GLuint[g->NumTextures];
|
||||
glGenTextures(g->NumTextures, textures[c]);
|
||||
MakeTextures2(g, textures[c][j * tw + i], NULL, GLMaxTextureSize * i, GLMaxTextureSize * j);
|
||||
ColorCycleSurface(*g->Surface);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Make an OpenGL texture with the player colors.
|
||||
**
|
||||
** @param g The graphic to texture with player colors.
|
||||
** @param player Player number to make textures for.
|
||||
*/
|
||||
void MakePlayerColorTexture(CPlayerColorGraphic *g, int player)
|
||||
{
|
||||
if (g->PlayerColorTextures[player]) {
|
||||
return;
|
||||
}
|
||||
|
||||
MakeTextures(g, player, &Players[player].UnitColors);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
** Resize a graphic
|
||||
**
|
||||
|
@ -1480,17 +945,6 @@ void CGraphic::Resize(int w, int h)
|
|||
Width = GraphicWidth = w;
|
||||
Height = GraphicHeight = h;
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL && Textures) {
|
||||
glDeleteTextures(NumTextures, Textures);
|
||||
delete[] Textures;
|
||||
Textures = NULL;
|
||||
MakeTexture(this);
|
||||
if (DeleteColorCyclingTextures()) {
|
||||
MakeColorCyclingTextures(this, NumColorCycles);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
GenFramesMap();
|
||||
}
|
||||
|
||||
|
@ -1513,26 +967,12 @@ void CGraphic::SetOriginalSize()
|
|||
}
|
||||
delete[] frame_map;
|
||||
frame_map = NULL;
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (!UseOpenGL)
|
||||
#endif
|
||||
{
|
||||
if (SurfaceFlip) {
|
||||
FreeSurface(&SurfaceFlip);
|
||||
SurfaceFlip = NULL;
|
||||
}
|
||||
delete[] frameFlip_map;
|
||||
frameFlip_map = NULL;
|
||||
if (SurfaceFlip) {
|
||||
FreeSurface(&SurfaceFlip);
|
||||
SurfaceFlip = NULL;
|
||||
}
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL && Textures) {
|
||||
glDeleteTextures(NumTextures, Textures);
|
||||
delete[] Textures;
|
||||
Textures = NULL;
|
||||
DeleteColorCyclingTextures();
|
||||
}
|
||||
#endif
|
||||
delete[] frameFlip_map;
|
||||
frameFlip_map = NULL;
|
||||
|
||||
this->Width = this->Height = 0;
|
||||
this->Surface = NULL;
|
||||
|
@ -1593,22 +1033,9 @@ void CGraphic::MakeShadow()
|
|||
SDL_SetPaletteColors(Surface->format->palette, colors, 0, 256);
|
||||
SDL_SetSurfaceAlphaMod(Surface, 128);
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
if (Textures) {
|
||||
glDeleteTextures(NumTextures, Textures);
|
||||
delete[] Textures;
|
||||
Textures = NULL;
|
||||
DeleteColorCyclingTextures();
|
||||
}
|
||||
MakeTexture(this);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
if (SurfaceFlip) {
|
||||
SDL_SetPaletteColors(SurfaceFlip->format->palette, colors, 0, 256);
|
||||
SDL_SetSurfaceAlphaMod(SurfaceFlip, 128);
|
||||
}
|
||||
if (SurfaceFlip) {
|
||||
SDL_SetPaletteColors(SurfaceFlip->format->palette, colors, 0, 256);
|
||||
SDL_SetSurfaceAlphaMod(SurfaceFlip, 128);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1733,17 +1160,4 @@ void CFiller::Load()
|
|||
}
|
||||
}
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
bool CGraphic::DeleteColorCyclingTextures() {
|
||||
if (!ColorCyclingTextures) return false;
|
||||
for (int i = 1; i < NumColorCycles; i++) {
|
||||
// first one is the default and already free'd
|
||||
glDeleteTextures(NumTextures, ColorCyclingTextures[i]);
|
||||
// glDeleteTextures already deletes the array
|
||||
}
|
||||
delete[] ColorCyclingTextures;
|
||||
ColorCyclingTextures = NULL;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
//@}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,352 +0,0 @@
|
|||
// _________ __ __
|
||||
// / _____// |_____________ _/ |______ ____ __ __ ______
|
||||
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
|
||||
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
|
||||
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
||||
// \/ \/ \//_____/ \/
|
||||
// ______________________ ______________________
|
||||
// T H E W A R B E G I N S
|
||||
// Stratagus - A free fantasy real time strategy game engine
|
||||
//
|
||||
/**@name mng.cpp - The mng graphic file loader. */
|
||||
//
|
||||
// (c) Copyright 2004-2005 by Jimmy Salmon
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; only version 2 of the License.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
// 02111-1307, USA.
|
||||
//
|
||||
|
||||
//@{
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Includes
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "stratagus.h"
|
||||
|
||||
#ifdef USE_MNG
|
||||
|
||||
#include "video.h"
|
||||
#include "iolib.h"
|
||||
#include "iocompat.h"
|
||||
|
||||
#include <libmng.h>
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Functions
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
static mng_ptr MNG_DECL my_alloc(mng_size_t len)
|
||||
{
|
||||
char *ptr = new char[len];
|
||||
memset(ptr, 0, len);
|
||||
return (mng_ptr)ptr;
|
||||
}
|
||||
|
||||
static void MNG_DECL my_free(mng_ptr ptr, mng_size_t)
|
||||
{
|
||||
delete[] static_cast<char *>(ptr);
|
||||
}
|
||||
|
||||
static mng_bool MNG_DECL my_openstream(mng_handle handle)
|
||||
{
|
||||
Mng *mng;
|
||||
|
||||
mng = (Mng *)mng_get_userdata(handle);
|
||||
mng->fd = fopen(mng->name.c_str(), "rb");
|
||||
if (!mng->fd) {
|
||||
return MNG_FALSE;
|
||||
}
|
||||
return MNG_TRUE;
|
||||
}
|
||||
|
||||
static mng_bool MNG_DECL my_closestream(mng_handle handle)
|
||||
{
|
||||
Mng *mng;
|
||||
|
||||
mng = (Mng *)mng_get_userdata(handle);
|
||||
if (mng->fd) {
|
||||
fclose(mng->fd);
|
||||
}
|
||||
return MNG_TRUE;
|
||||
}
|
||||
|
||||
static mng_bool MNG_DECL my_readdata(mng_handle handle, mng_ptr buf, mng_uint32 buflen,
|
||||
mng_uint32p read)
|
||||
{
|
||||
Mng *mng;
|
||||
|
||||
mng = (Mng *)mng_get_userdata(handle);
|
||||
*read = fread(buf, 1, buflen, mng->fd);
|
||||
return MNG_TRUE;
|
||||
}
|
||||
|
||||
static mng_bool MNG_DECL my_processheader(mng_handle handle, mng_uint32 width,
|
||||
mng_uint32 height)
|
||||
{
|
||||
mng_imgtype type = mng_get_sigtype(handle);
|
||||
if (type != mng_it_mng) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Mng *mng = (Mng *)mng_get_userdata(handle);
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
unsigned w;
|
||||
unsigned h;
|
||||
for (w = 1; w < width; w <<= 1) {
|
||||
}
|
||||
for (h = 1; h < height; h <<= 1) {
|
||||
}
|
||||
mng->texture_width = (float)width / w;
|
||||
mng->texture_height = (float)height / h;
|
||||
glGenTextures(1, &mng->texture_name);
|
||||
glBindTexture(GL_TEXTURE_2D, mng->texture_name);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Allocate the SDL surface to hold the image
|
||||
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||
const Uint32 Rmask = 0x000000FF;
|
||||
const Uint32 Gmask = 0x0000FF00;
|
||||
const Uint32 Bmask = 0x00FF0000;
|
||||
#else
|
||||
const Uint32 Rmask = 0xFF000000 >> 8;
|
||||
const Uint32 Gmask = 0x00FF0000 >> 8;
|
||||
const Uint32 Bmask = 0x0000FF00 >> 8;
|
||||
#endif
|
||||
|
||||
mng->buffer = new unsigned char[width * height * 3];
|
||||
memset(mng->buffer, width * height * 3, sizeof(unsigned char));
|
||||
|
||||
mng->surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
|
||||
8 * 3, Rmask, Gmask, Bmask, 0);
|
||||
if (mng->surface == NULL) {
|
||||
fprintf(stderr, "Out of memory");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return MNG_TRUE;
|
||||
}
|
||||
|
||||
static mng_ptr MNG_DECL my_getcanvasline(mng_handle handle, mng_uint32 linenr)
|
||||
{
|
||||
Mng *mng;
|
||||
|
||||
mng = (Mng *)mng_get_userdata(handle);
|
||||
return mng->buffer + linenr * mng->surface->w * 3;
|
||||
}
|
||||
|
||||
static mng_bool MNG_DECL my_refresh(mng_handle handle, mng_uint32, mng_uint32,
|
||||
mng_uint32, mng_uint32)
|
||||
{
|
||||
Mng *mng = (Mng *)mng_get_userdata(handle);
|
||||
SDL_LockSurface(mng->surface);
|
||||
for (int i = 0; i < mng->surface->h; ++i) {
|
||||
memcpy((char *)mng->surface->pixels + i * mng->surface->pitch,
|
||||
mng->buffer + i * mng->surface->w * 3, mng->surface->w * 3);
|
||||
}
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
glBindTexture(GL_TEXTURE_2D, mng->texture_name);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, mng->surface->w, mng->surface->h,
|
||||
GL_RGB, GL_UNSIGNED_BYTE, mng->surface->pixels);
|
||||
}
|
||||
#endif
|
||||
SDL_UnlockSurface(mng->surface);
|
||||
|
||||
return MNG_TRUE;
|
||||
}
|
||||
|
||||
static mng_uint32 MNG_DECL my_gettickcount(mng_handle)
|
||||
{
|
||||
return GetTicks();
|
||||
}
|
||||
|
||||
static mng_bool MNG_DECL my_settimer(mng_handle handle, mng_uint32 msecs)
|
||||
{
|
||||
Mng *mng = (Mng *)mng_get_userdata(handle);
|
||||
mng->ticks = GetTicks() + msecs;
|
||||
|
||||
return MNG_TRUE;
|
||||
}
|
||||
|
||||
static mng_bool MNG_DECL my_processmend(mng_handle handle, mng_uint32 iterationsdone,
|
||||
mng_uint32)
|
||||
{
|
||||
Mng *mng = (Mng *)mng_get_userdata(handle);
|
||||
mng->iteration = iterationsdone;
|
||||
|
||||
return MNG_TRUE;
|
||||
}
|
||||
|
||||
static mng_bool MNG_DECL my_errorproc(mng_handle handle, mng_int32,
|
||||
mng_int8, mng_chunkid, mng_uint32, mng_int32, mng_int32, mng_pchar errortext)
|
||||
{
|
||||
Mng *mng = (Mng *)mng_get_userdata(handle);
|
||||
mng->iteration = 0x7fffffff;
|
||||
if (errortext) {
|
||||
DebugPrint("MNG error: %s\n" _C_ errortext);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
Mng::Mng() :
|
||||
name(NULL), fd(NULL), handle(NULL), surface(NULL), buffer(NULL),
|
||||
ticks(0), iteration(0)
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
texture_width = texture_height = texture_name = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Mng::~Mng()
|
||||
{
|
||||
// delete[] name;
|
||||
if (handle) {
|
||||
mng_cleanup(&handle);
|
||||
}
|
||||
if (surface) {
|
||||
SDL_FreeSurface(surface);
|
||||
}
|
||||
delete[] buffer;
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL && texture_width) {
|
||||
glDeleteTextures(1, &texture_name);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
** Display a MNG
|
||||
**
|
||||
** @param x X coordinate
|
||||
** @param y Y coordinate
|
||||
*/
|
||||
void Mng::Draw(int x, int y)
|
||||
{
|
||||
if (ticks <= GetTicks()) {
|
||||
mng_display_resume(handle);
|
||||
}
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
GLint sx = x;
|
||||
GLint ex = sx + surface->w;
|
||||
GLint sy = y;
|
||||
GLint ey = sy + surface->h;
|
||||
|
||||
#ifdef USE_GLES
|
||||
float texCoord[] = {
|
||||
0.0f, 0.0f,
|
||||
texture_width, 0.0f,
|
||||
0.0f, texture_height,
|
||||
texture_width, texture_height
|
||||
};
|
||||
|
||||
float vertex[] = {
|
||||
2.0f / (GLfloat)Video.Width *sx - 1.0f, -2.0f / (GLfloat)Video.Height *sy + 1.0f,
|
||||
2.0f / (GLfloat)Video.Width *ex - 1.0f, -2.0f / (GLfloat)Video.Height *sy + 1.0f,
|
||||
2.0f / (GLfloat)Video.Width *sx - 1.0f, -2.0f / (GLfloat)Video.Height *ey + 1.0f,
|
||||
2.0f / (GLfloat)Video.Width *ex - 1.0f, -2.0f / (GLfloat)Video.Height *ey + 1.0f
|
||||
};
|
||||
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, texCoord);
|
||||
glVertexPointer(2, GL_FLOAT, 0, vertex);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
#endif
|
||||
#ifdef USE_OPENGL
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0.0f, 0.0f);
|
||||
glVertex2i(sx, sy);
|
||||
glTexCoord2f(0.0f, texture_height);
|
||||
glVertex2i(sx, ey);
|
||||
glTexCoord2f(texture_width, texture_height);
|
||||
glVertex2i(ex, ey);
|
||||
glTexCoord2f(texture_width, 0.0f);
|
||||
glVertex2i(ex, sy);
|
||||
glEnd();
|
||||
#endif
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
SDL_Rect rect = {(short int)x, (short int)y, (short unsigned int)(surface->w), (short unsigned int)(surface->h)};
|
||||
SDL_BlitSurface(surface, NULL, TheScreen, &rect);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Load a MNG
|
||||
**
|
||||
** @param name Name of the MNG file
|
||||
*/
|
||||
int Mng::Load(const std::string &name)
|
||||
{
|
||||
this->name = LibraryFileName(name.c_str());
|
||||
handle = mng_initialize(this, my_alloc, my_free, MNG_NULL);
|
||||
if (handle == MNG_NULL) {
|
||||
return -1;
|
||||
}
|
||||
mng_setcb_openstream(handle, my_openstream);
|
||||
mng_setcb_closestream(handle, my_closestream);
|
||||
mng_setcb_readdata(handle, my_readdata);
|
||||
mng_setcb_processheader(handle, my_processheader);
|
||||
mng_setcb_processmend(handle, my_processmend);
|
||||
mng_setcb_getcanvasline(handle, my_getcanvasline);
|
||||
mng_setcb_refresh(handle, my_refresh);
|
||||
mng_setcb_gettickcount(handle, my_gettickcount);
|
||||
mng_setcb_settimer(handle, my_settimer);
|
||||
mng_setcb_errorproc(handle, my_errorproc);
|
||||
|
||||
mng_read(handle);
|
||||
if (surface && iteration != 0x7fffffff) {
|
||||
mng_display(handle);
|
||||
}
|
||||
|
||||
if (!surface || iteration == 0x7fffffff) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
** Reset a MNG
|
||||
*/
|
||||
void Mng::Reset()
|
||||
{
|
||||
mng_display_reset(handle);
|
||||
iteration = 0;
|
||||
mng_display(handle);
|
||||
}
|
||||
|
||||
#endif // USE_MNG
|
||||
|
||||
//@}
|
|
@ -178,13 +178,8 @@ static int TheoraProcessData(OggData *data)
|
|||
int PlayMovie(const std::string &name)
|
||||
{
|
||||
int videoWidth, videoHeight;
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
videoWidth = Video.ViewportWidth;
|
||||
videoHeight = Video.ViewportHeight;
|
||||
#else
|
||||
videoWidth = Video.Width;
|
||||
videoHeight = Video.Height;
|
||||
#endif
|
||||
|
||||
const std::string filename = LibraryFileName(name.c_str());
|
||||
|
||||
|
@ -217,14 +212,6 @@ int PlayMovie(const std::string &name)
|
|||
rect.y = 0;
|
||||
}
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
// When SDL_OPENGL is used, it is not possible to call SDL_CreateYUVOverlay, so turn temporary OpenGL off
|
||||
// With GLES is all ok
|
||||
if (UseOpenGL) {
|
||||
//SDL_SetVideoMode(Video.ViewportWidth, Video.ViewportHeight, Video.Depth, SDL_GetVideoSurface()->flags & ~SDL_OPENGL);
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_RenderClear(TheRenderer);
|
||||
Video.ClearScreen();
|
||||
SDL_Texture *yuv_overlay = SDL_CreateTexture(TheRenderer,
|
||||
|
@ -297,13 +284,6 @@ int PlayMovie(const std::string &name)
|
|||
OggFree(&data);
|
||||
f.close();
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
if (UseOpenGL) {
|
||||
//SDL_SetVideoMode(Video.ViewportWidth, Video.ViewportHeight, Video.Depth, SDL_GetVideoSurface()->flags | SDL_OPENGL);
|
||||
ReloadOpenGL();
|
||||
}
|
||||
#endif
|
||||
|
||||
SetCallbacks(old_callbacks);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -321,17 +321,8 @@ void SaveScreenshotPNG(const char *name)
|
|||
png_init_io(png_ptr, fp);
|
||||
|
||||
int pngw, pngh;
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
pngw = Video.ViewportWidth;
|
||||
pngh = Video.ViewportHeight;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
pngw = Video.Width;
|
||||
pngh = Video.Height;
|
||||
}
|
||||
pngw = Video.ViewportWidth;
|
||||
pngh = Video.ViewportHeight;
|
||||
png_set_IHDR(png_ptr, info_ptr, pngw, pngh, 8,
|
||||
PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
|
||||
PNG_FILTER_TYPE_DEFAULT);
|
||||
|
@ -340,60 +331,37 @@ void SaveScreenshotPNG(const char *name)
|
|||
|
||||
png_write_info(png_ptr, info_ptr);
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
unsigned char* pixels = new unsigned char[Video.ViewportWidth * Video.ViewportHeight * 3];
|
||||
if (GLShaderPipelineSupported) {
|
||||
// switch to real display
|
||||
glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
|
||||
}
|
||||
#ifdef USE_OPENGL
|
||||
glReadBuffer(GL_FRONT);
|
||||
#endif
|
||||
glReadPixels(0, 0, Video.ViewportWidth, Video.ViewportHeight, GL_RGB, GL_UNSIGNED_BYTE, pixels);
|
||||
if (GLShaderPipelineSupported) {
|
||||
// switch back to framebuffer
|
||||
glBindFramebuffer(GL_FRAMEBUFFER_EXT, fullscreenFramebuffer);
|
||||
}
|
||||
for (int i = 0; i < Video.ViewportHeight; ++i) {
|
||||
png_write_row(png_ptr, &pixels[(Video.ViewportHeight - 1 - i) * Video.ViewportWidth * 3]);
|
||||
}
|
||||
delete []pixels;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
std::vector<unsigned char> row;
|
||||
SDL_PixelFormat *fmt = TheScreen->format;
|
||||
std::vector<unsigned char> row;
|
||||
SDL_PixelFormat *fmt = TheScreen->format;
|
||||
|
||||
row.resize(Video.Width * 3);
|
||||
for (int i = 0; i < Video.Height; ++i) {
|
||||
switch (Video.Depth) {
|
||||
case 15:
|
||||
case 16: {
|
||||
for (int j = 0; j < Video.Width; ++j) {
|
||||
Uint16 c = ((Uint16 *)TheScreen->pixels)[j + i * Video.Width];
|
||||
row[j * 3 + 0] = ((c & fmt->Rmask) >> fmt->Rshift) << fmt->Rloss;
|
||||
row[j * 3 + 1] = ((c & fmt->Gmask) >> fmt->Gshift) << fmt->Gloss;
|
||||
row[j * 3 + 2] = ((c & fmt->Bmask) >> fmt->Bshift) << fmt->Bloss;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 24: {
|
||||
memcpy(&row[0], (char *)TheScreen->pixels + i * Video.Width, Video.Width * 3);
|
||||
break;
|
||||
}
|
||||
case 32: {
|
||||
for (int j = 0; j < Video.Width; ++j) {
|
||||
Uint32 c = ((Uint32 *)TheScreen->pixels)[j + i * Video.Width];
|
||||
row[j * 3 + 0] = ((c & fmt->Rmask) >> fmt->Rshift);
|
||||
row[j * 3 + 1] = ((c & fmt->Gmask) >> fmt->Gshift);
|
||||
row[j * 3 + 2] = ((c & fmt->Bmask) >> fmt->Bshift);
|
||||
}
|
||||
break;
|
||||
}
|
||||
row.resize(Video.Width * 3);
|
||||
for (int i = 0; i < Video.Height; ++i) {
|
||||
switch (Video.Depth) {
|
||||
case 15:
|
||||
case 16: {
|
||||
for (int j = 0; j < Video.Width; ++j) {
|
||||
Uint16 c = ((Uint16 *)TheScreen->pixels)[j + i * Video.Width];
|
||||
row[j * 3 + 0] = ((c & fmt->Rmask) >> fmt->Rshift) << fmt->Rloss;
|
||||
row[j * 3 + 1] = ((c & fmt->Gmask) >> fmt->Gshift) << fmt->Gloss;
|
||||
row[j * 3 + 2] = ((c & fmt->Bmask) >> fmt->Bshift) << fmt->Bloss;
|
||||
}
|
||||
png_write_row(png_ptr, &row[0]);
|
||||
break;
|
||||
}
|
||||
case 24: {
|
||||
memcpy(&row[0], (char *)TheScreen->pixels + i * Video.Width, Video.Width * 3);
|
||||
break;
|
||||
}
|
||||
case 32: {
|
||||
for (int j = 0; j < Video.Width; ++j) {
|
||||
Uint32 c = ((Uint32 *)TheScreen->pixels)[j + i * Video.Width];
|
||||
row[j * 3 + 0] = ((c & fmt->Rmask) >> fmt->Rshift);
|
||||
row[j * 3 + 1] = ((c & fmt->Gmask) >> fmt->Gshift);
|
||||
row[j * 3 + 2] = ((c & fmt->Bmask) >> fmt->Bshift);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
png_write_row(png_ptr, &row[0]);
|
||||
}
|
||||
|
||||
png_write_end(png_ptr, info_ptr);
|
||||
|
|
|
@ -56,20 +56,6 @@
|
|||
#include "SDL.h"
|
||||
#include "SDL_syswm.h"
|
||||
|
||||
#ifdef USE_GLES_EGL
|
||||
#include "EGL/egl.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_GLES
|
||||
#include "GLES/gl.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
#define __gl_glext_h_
|
||||
#include "SDL_opengl.h"
|
||||
#include "shaders.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_BEOS
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
@ -101,11 +87,6 @@
|
|||
-- Variables
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef USE_GLES_EGL
|
||||
static EGLDisplay eglDisplay;
|
||||
static EGLSurface eglSurface;
|
||||
#endif
|
||||
|
||||
SDL_Window *TheWindow; /// Internal screen
|
||||
SDL_Renderer *TheRenderer = NULL; /// Internal screen
|
||||
SDL_Texture *TheTexture; /// Internal screen
|
||||
|
@ -114,13 +95,6 @@ SDL_Surface *TheScreen; /// Internal screen
|
|||
static SDL_Rect Rects[100];
|
||||
static int NumRects;
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
GLint GLMaxTextureSize = 256; /// Max texture size supported on the video card
|
||||
GLint GLMaxTextureSizeOverride; /// User-specified limit for ::GLMaxTextureSize
|
||||
bool GLTextureCompressionSupported; /// Is OpenGL texture compression supported
|
||||
bool UseGLTextureCompression; /// Use OpenGL texture compression
|
||||
#endif
|
||||
|
||||
static std::map<int, std::string> Key2Str;
|
||||
static std::map<std::string, int> Str2Key;
|
||||
|
||||
|
@ -131,21 +105,6 @@ const EventCallback *Callbacks;
|
|||
static bool RegenerateScreen = false;
|
||||
bool IsSDLWindowVisible = true;
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Functions
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
// ARB_texture_compression
|
||||
#ifdef USE_OPENGL
|
||||
PFNGLCOMPRESSEDTEXIMAGE3DARBPROC glCompressedTexImage3DARB;
|
||||
PFNGLCOMPRESSEDTEXIMAGE2DARBPROC glCompressedTexImage2DARB;
|
||||
PFNGLCOMPRESSEDTEXIMAGE1DARBPROC glCompressedTexImage1DARB;
|
||||
PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC glCompressedTexSubImage3DARB;
|
||||
PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC glCompressedTexSubImage2DARB;
|
||||
PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC glCompressedTexSubImage1DARB;
|
||||
PFNGLGETCOMPRESSEDTEXIMAGEARBPROC glGetCompressedTexImageARB;
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Sync
|
||||
----------------------------------------------------------------------------*/
|
||||
|
@ -179,180 +138,6 @@ void SetVideoSync()
|
|||
-- Video
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
/**
|
||||
** Check if an extension is supported
|
||||
*/
|
||||
static bool IsExtensionSupported(const char *extension)
|
||||
{
|
||||
const GLubyte *extensions = NULL;
|
||||
const GLubyte *start;
|
||||
GLubyte *ptr, *terminator;
|
||||
int len;
|
||||
|
||||
// Extension names should not have spaces.
|
||||
ptr = (GLubyte *)strchr(extension, ' ');
|
||||
if (ptr || *extension == '\0') {
|
||||
return false;
|
||||
}
|
||||
|
||||
extensions = glGetString(GL_EXTENSIONS);
|
||||
len = strlen(extension);
|
||||
start = extensions;
|
||||
while (true) {
|
||||
if (!start)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
ptr = (GLubyte *)strstr((const char *)start, extension);
|
||||
if (!ptr) {
|
||||
break;
|
||||
}
|
||||
|
||||
terminator = ptr + len;
|
||||
if (ptr == start || *(ptr - 1) == ' ') {
|
||||
if (*terminator == ' ' || *terminator == '\0') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
start = terminator;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
|
||||
/**
|
||||
** Initialize OpenGL extensions
|
||||
*/
|
||||
static void InitOpenGLExtensions()
|
||||
{
|
||||
// ARB_texture_compression
|
||||
#ifdef USE_OPENGL
|
||||
if (IsExtensionSupported("GL_ARB_texture_compression")) {
|
||||
glCompressedTexImage3DARB =
|
||||
(PFNGLCOMPRESSEDTEXIMAGE3DARBPROC)(uintptr_t)SDL_GL_GetProcAddress("glCompressedTexImage3DARB");
|
||||
glCompressedTexImage2DARB =
|
||||
(PFNGLCOMPRESSEDTEXIMAGE2DARBPROC)(uintptr_t)SDL_GL_GetProcAddress("glCompressedTexImage2DARB");
|
||||
glCompressedTexImage1DARB =
|
||||
(PFNGLCOMPRESSEDTEXIMAGE1DARBPROC)(uintptr_t)SDL_GL_GetProcAddress("glCompressedTexImage1DARB");
|
||||
glCompressedTexSubImage3DARB =
|
||||
(PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC)(uintptr_t)SDL_GL_GetProcAddress("glCompressedTexSubImage3DARB");
|
||||
glCompressedTexSubImage2DARB =
|
||||
(PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC)(uintptr_t)SDL_GL_GetProcAddress("glCompressedTexSubImage2DARB");
|
||||
glCompressedTexSubImage1DARB =
|
||||
(PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC)(uintptr_t)SDL_GL_GetProcAddress("glCompressedTexSubImage1DARB");
|
||||
glGetCompressedTexImageARB =
|
||||
(PFNGLGETCOMPRESSEDTEXIMAGEARBPROC)(uintptr_t)SDL_GL_GetProcAddress("glGetCompressedTexImageARB");
|
||||
|
||||
if (glCompressedTexImage3DARB && glCompressedTexImage2DARB &&
|
||||
glCompressedTexImage1DARB && glCompressedTexSubImage3DARB &&
|
||||
glCompressedTexSubImage2DARB && glCompressedTexSubImage1DARB &&
|
||||
glGetCompressedTexImageARB) {
|
||||
GLTextureCompressionSupported = true;
|
||||
} else {
|
||||
GLTextureCompressionSupported = false;
|
||||
}
|
||||
} else {
|
||||
GLTextureCompressionSupported = false;
|
||||
}
|
||||
|
||||
GLShaderPipelineSupported = GLShaderPipelineSupported && LoadShaderExtensions();
|
||||
#else
|
||||
GLTextureCompressionSupported = false;
|
||||
GLShaderPipelineSupported = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
** Initialize OpenGL
|
||||
*/
|
||||
static void InitOpenGL()
|
||||
{
|
||||
|
||||
InitOpenGLExtensions();
|
||||
|
||||
glViewport(0, 0, (GLsizei)Video.ViewportWidth, (GLsizei)Video.ViewportHeight);
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
#endif
|
||||
|
||||
#ifdef USE_GLES
|
||||
glOrthof(0.0f, (GLfloat)Video.Width, (GLfloat)Video.Height, 0.0f, -1.0f, 1.0f);
|
||||
#endif
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
if (!GLShaderPipelineSupported) {
|
||||
glOrtho(0, Video.Width, Video.Height, 0, -1, 1);
|
||||
} else {
|
||||
glOrtho(0, Video.ViewportWidth, Video.ViewportHeight, 0, -1, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
glMatrixMode(GL_TEXTURE);
|
||||
glLoadIdentity();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
glTranslatef(0.375, 0.375, 0.);
|
||||
#endif
|
||||
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
#ifdef USE_GLES
|
||||
glClearDepthf(1.0f);
|
||||
#endif
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
glClearDepth(1.0f);
|
||||
|
||||
if (GLShaderPipelineSupported) {
|
||||
SetupFramebuffer();
|
||||
}
|
||||
#endif
|
||||
|
||||
glShadeModel(GL_FLAT);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_BLEND);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
|
||||
|
||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &GLMaxTextureSize);
|
||||
if (GLMaxTextureSize == 0) {
|
||||
// FIXME: try to use GL_PROXY_TEXTURE_2D to get a valid size
|
||||
#if 0
|
||||
glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGBA, size, size, 0,
|
||||
GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||
glGetTexLevelParameterfv(GL_PROXY_TEXTURE_2D, 0,
|
||||
GL_TEXTURE_INTERNAL_FORMAT, &internalFormat);
|
||||
#endif
|
||||
fprintf(stderr, "GL_MAX_TEXTURE_SIZE is 0, using 256 by default\n");
|
||||
GLMaxTextureSize = 256;
|
||||
}
|
||||
if (GLMaxTextureSize > GLMaxTextureSizeOverride
|
||||
&& GLMaxTextureSizeOverride > 0) {
|
||||
GLMaxTextureSize = GLMaxTextureSizeOverride;
|
||||
}
|
||||
}
|
||||
|
||||
void ReloadOpenGL()
|
||||
{
|
||||
InitOpenGL();
|
||||
ReloadGraphics();
|
||||
ReloadFonts();
|
||||
UI.Minimap.Reload();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(DEBUG) && !defined(USE_WIN32)
|
||||
static void CleanExit(int)
|
||||
{
|
||||
|
@ -522,10 +307,6 @@ void InitVideoSdl()
|
|||
|
||||
// Initialize the display
|
||||
|
||||
#if !defined(USE_OPENGL) && !defined(USE_GLES)
|
||||
flags = 0;
|
||||
#endif
|
||||
|
||||
// Sam said: better for windows.
|
||||
/* SDL_HWSURFACE|SDL_HWPALETTE | */
|
||||
if (Video.FullScreen) {
|
||||
|
@ -534,17 +315,6 @@ void InitVideoSdl()
|
|||
flags |= SDL_WINDOW_RESIZABLE;
|
||||
}
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
#ifdef USE_GLES_NATIVE
|
||||
flags |= SDL_OPENGLES;
|
||||
#endif
|
||||
#ifdef USE_OPENGL
|
||||
flags |= SDL_OPENGL | SDL_GL_DOUBLEBUFFER;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
if (true || !Video.Width || !Video.Height) {
|
||||
Video.ViewportWidth = Video.Width;
|
||||
Video.ViewportHeight = Video.Height;
|
||||
|
@ -574,14 +344,6 @@ void InitVideoSdl()
|
|||
if (TheWindow == NULL) {
|
||||
fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n",
|
||||
Video.Width, Video.Height, Video.Depth, SDL_GetError());
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
fprintf(stderr, "Re-trying video without OpenGL\n");
|
||||
UseOpenGL = false;
|
||||
InitVideoSdl();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (Video.FullScreen) {
|
||||
fprintf(stderr, "Re-trying video without fullscreen mode\n");
|
||||
Video.FullScreen = false;
|
||||
|
@ -603,15 +365,10 @@ void InitVideoSdl()
|
|||
SDL_PIXELFORMAT_ARGB8888,
|
||||
SDL_TEXTUREACCESS_STREAMING,
|
||||
Video.Width, Video.Height);
|
||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0");
|
||||
|
||||
#if ! defined(USE_WIN32) && ! defined(USE_MAEMO)
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
// Make sure, that we not create OpenGL textures (and do not call OpenGL functions), when creating icon surface
|
||||
bool UseOpenGL_orig = UseOpenGL;
|
||||
UseOpenGL = false;
|
||||
#endif
|
||||
|
||||
SDL_Surface *icon = NULL;
|
||||
CGraphic *g = NULL;
|
||||
struct stat st;
|
||||
|
@ -659,88 +416,16 @@ void InitVideoSdl()
|
|||
CGraphic::Free(g);
|
||||
}
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
UseOpenGL = UseOpenGL_orig;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Video.FullScreen = (SDL_GetWindowFlags(TheWindow) & SDL_WINDOW_FULLSCREEN_DESKTOP) ? 1 : 0;
|
||||
Video.Depth = TheScreen->format->BitsPerPixel;
|
||||
|
||||
//Wyrmgus start
|
||||
//#if defined(USE_TOUCHSCREEN) && defined(USE_WIN32)
|
||||
//Wyrmgus end
|
||||
// Must not allow SDL to switch to relative mouse coordinates
|
||||
// with touchscreen when going fullscreen. So we don't hide the
|
||||
// cursor, but instead set a transparent 1px cursor
|
||||
// Must not allow SDL to switch to relative mouse coordinates when going
|
||||
// fullscreen. So we don't hide the cursor, but instead set a transparent
|
||||
// 1px cursor
|
||||
Uint8 emptyCursor[] = {'\0'};
|
||||
Video.blankCursor = SDL_CreateCursor(emptyCursor, emptyCursor, 1, 1, 0, 0);
|
||||
SDL_SetCursor(Video.blankCursor);
|
||||
//Wyrmgus start
|
||||
//#else
|
||||
//Wyrmgus end
|
||||
// Turn cursor off, we use our own.
|
||||
//Wyrmgus start
|
||||
// SDL_ShowCursor(SDL_DISABLE);
|
||||
//Wyrmgus end
|
||||
//Wyrmgus start
|
||||
//#endif
|
||||
//Wyrmgus end
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
#ifdef USE_GLES_EGL
|
||||
// Get the SDL window handle
|
||||
SDL_SysWMinfo sysInfo; //Will hold our Window information
|
||||
SDL_VERSION(&sysInfo.version); //Set SDL version
|
||||
if (SDL_GetWMInfo(&sysInfo) <= 0) {
|
||||
fprintf(stderr, "Unable to get window handle\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
eglDisplay = eglGetDisplay((EGLNativeDisplayType)sysInfo.info.x11.display);
|
||||
if (!eglDisplay) {
|
||||
fprintf(stderr, "Couldn't open EGL Display\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!eglInitialize(eglDisplay, NULL, NULL)) {
|
||||
fprintf(stderr, "Couldn't initialize EGL Display\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Find a matching config
|
||||
EGLint configAttribs[] = {EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE};
|
||||
EGLint numConfigsOut = 0;
|
||||
EGLConfig eglConfig;
|
||||
if (eglChooseConfig(eglDisplay, configAttribs, &eglConfig, 1, &numConfigsOut) != EGL_TRUE || numConfigsOut == 0) {
|
||||
fprintf(stderr, "Unable to find appropriate EGL config\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, (EGLNativeWindowType)sysInfo.info.x11.window, 0);
|
||||
if (eglSurface == EGL_NO_SURFACE) {
|
||||
fprintf(stderr, "Unable to create EGL surface\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Bind GLES and create the context
|
||||
eglBindAPI(EGL_OPENGL_ES_API);
|
||||
EGLint contextParams[] = {EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE};
|
||||
EGLContext eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, NULL);
|
||||
if (eglContext == EGL_NO_CONTEXT) {
|
||||
fprintf(stderr, "Unable to create GLES context\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext) == EGL_FALSE) {
|
||||
fprintf(stderr, "Unable to make GLES context current\n");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
InitOpenGL();
|
||||
}
|
||||
#endif
|
||||
|
||||
InitKey2Str();
|
||||
|
||||
|
@ -786,18 +471,13 @@ int VideoValidResolution(int w, int h)
|
|||
*/
|
||||
void InvalidateArea(int x, int y, int w, int h)
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (!UseOpenGL)
|
||||
#endif
|
||||
{
|
||||
Assert(NumRects != sizeof(Rects) / sizeof(*Rects));
|
||||
Assert(x >= 0 && y >= 0 && x + w <= Video.Width && y + h <= Video.Height);
|
||||
Rects[NumRects].x = x;
|
||||
Rects[NumRects].y = y;
|
||||
Rects[NumRects].w = w;
|
||||
Rects[NumRects].h = h;
|
||||
++NumRects;
|
||||
}
|
||||
Assert(NumRects != sizeof(Rects) / sizeof(*Rects));
|
||||
Assert(x >= 0 && y >= 0 && x + w <= Video.Width && y + h <= Video.Height);
|
||||
Rects[NumRects].x = x;
|
||||
Rects[NumRects].y = y;
|
||||
Rects[NumRects].w = w;
|
||||
Rects[NumRects].h = h;
|
||||
++NumRects;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -805,25 +485,15 @@ void InvalidateArea(int x, int y, int w, int h)
|
|||
*/
|
||||
void Invalidate()
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (!UseOpenGL)
|
||||
#endif
|
||||
{
|
||||
Rects[0].x = 0;
|
||||
Rects[0].y = 0;
|
||||
Rects[0].w = Video.Width;
|
||||
Rects[0].h = Video.Height;
|
||||
NumRects = 1;
|
||||
}
|
||||
Rects[0].x = 0;
|
||||
Rects[0].y = 0;
|
||||
Rects[0].w = Video.Width;
|
||||
Rects[0].h = Video.Height;
|
||||
NumRects = 1;
|
||||
}
|
||||
|
||||
// Switch to the shader currently stored in Video.ShaderIndex without changing it
|
||||
void SwitchToShader() {
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (TheScreen && UseOpenGL && GLShaderPipelineSupported) {
|
||||
LoadShaders(0, NULL);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -834,13 +504,6 @@ void SwitchToShader() {
|
|||
*/
|
||||
static void SdlDoEvent(const EventCallback &callbacks, SDL_Event &event)
|
||||
{
|
||||
#if (defined(USE_OPENGL) || defined(USE_GLES))
|
||||
// Scale mouse-coordinates to viewport
|
||||
if (ZoomNoResize && (event.type & (SDL_MOUSEBUTTONUP | SDL_MOUSEBUTTONDOWN | SDL_MOUSEMOTION))) {
|
||||
event.button.x = (Uint16)floorf(event.button.x * float(Video.Width) / Video.ViewportWidth);
|
||||
event.button.y = (Uint16)floorf(event.button.y * float(Video.Height) / Video.ViewportHeight);
|
||||
}
|
||||
#endif
|
||||
switch (event.type) {
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
InputMouseButtonPress(callbacks, SDL_GetTicks(), event.button.button);
|
||||
|
@ -1023,32 +686,15 @@ void WaitEventsOneFrame()
|
|||
*/
|
||||
void RealizeVideoMemory()
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
#ifdef USE_GLES_EGL
|
||||
eglSwapBuffers(eglDisplay, eglSurface);
|
||||
#endif
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES_NATIVE)
|
||||
if (GLShaderPipelineSupported) {
|
||||
RenderFramebufferToScreen();
|
||||
} else {
|
||||
SDL_GL_SwapWindow(TheWindow);
|
||||
}
|
||||
#endif
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
if (NumRects) {
|
||||
//SDL_UpdateWindowSurfaceRects(TheWindow, Rects, NumRects);
|
||||
SDL_UpdateTexture(TheTexture, NULL, TheScreen->pixels, TheScreen->pitch);
|
||||
//SDL_RenderClear(TheRenderer);
|
||||
//for (int i = 0; i < NumRects; i++)
|
||||
// SDL_UpdateTexture(TheTexture, &Rects[i], TheScreen->pixels, TheScreen->pitch);
|
||||
SDL_RenderCopy(TheRenderer, TheTexture, NULL, NULL);
|
||||
SDL_RenderPresent(TheRenderer);
|
||||
NumRects = 0;
|
||||
}
|
||||
if (NumRects) {
|
||||
//SDL_UpdateWindowSurfaceRects(TheWindow, Rects, NumRects);
|
||||
SDL_UpdateTexture(TheTexture, NULL, TheScreen->pixels, TheScreen->pitch);
|
||||
SDL_RenderClear(TheRenderer);
|
||||
//for (int i = 0; i < NumRects; i++)
|
||||
// SDL_UpdateTexture(TheTexture, &Rects[i], TheScreen->pixels, TheScreen->pitch);
|
||||
SDL_RenderCopy(TheRenderer, TheTexture, NULL, NULL);
|
||||
SDL_RenderPresent(TheRenderer);
|
||||
NumRects = 0;
|
||||
}
|
||||
HideCursor();
|
||||
}
|
||||
|
@ -1058,13 +704,8 @@ void RealizeVideoMemory()
|
|||
*/
|
||||
void SdlLockScreen()
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (!UseOpenGL)
|
||||
#endif
|
||||
{
|
||||
if (SDL_MUSTLOCK(TheScreen)) {
|
||||
SDL_LockSurface(TheScreen);
|
||||
}
|
||||
if (SDL_MUSTLOCK(TheScreen)) {
|
||||
SDL_LockSurface(TheScreen);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1073,13 +714,8 @@ void SdlLockScreen()
|
|||
*/
|
||||
void SdlUnlockScreen()
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (!UseOpenGL)
|
||||
#endif
|
||||
{
|
||||
if (SDL_MUSTLOCK(TheScreen)) {
|
||||
SDL_UnlockSurface(TheScreen);
|
||||
}
|
||||
if (SDL_MUSTLOCK(TheScreen)) {
|
||||
SDL_UnlockSurface(TheScreen);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1153,24 +789,6 @@ void ToggleFullScreen()
|
|||
}
|
||||
SDL_SetWindowFullscreen(TheWindow, flags ^ SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||
|
||||
#ifndef USE_TOUCHSCREEN
|
||||
// Cannot hide cursor on Windows with touchscreen, as it switches
|
||||
// to relative mouse coordinates in fullscreen. See above initial
|
||||
// call to ShowCursor
|
||||
//
|
||||
// Windows shows the SDL cursor when starting in fullscreen mode
|
||||
// then switching to window mode. This hides the cursor again.
|
||||
// tfel: this was for SDL1...
|
||||
//SDL_ShowCursor(SDL_ENABLE);
|
||||
//SDL_ShowCursor(SDL_DISABLE);
|
||||
#endif
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
ReloadOpenGL();
|
||||
}
|
||||
#endif
|
||||
|
||||
Invalidate(); // Update display
|
||||
#else // !USE_WIN32
|
||||
SDL_SetWindowFullscreen(TheWindow, flags ^ SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||
|
|
|
@ -1,295 +0,0 @@
|
|||
#include "stratagus.h"
|
||||
#include "parameters.h"
|
||||
#include "video.h"
|
||||
#include "game.h"
|
||||
#include "iolib.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
|
||||
#ifndef __APPLE__
|
||||
PFNGLCREATESHADERPROC glCreateShader;
|
||||
PFNGLSHADERSOURCEPROC glShaderSource;
|
||||
PFNGLCOMPILESHADERPROC glCompileShader;
|
||||
PFNGLCREATEPROGRAMPROC glCreateProgram;
|
||||
PFNGLATTACHSHADERPROC glAttachShader;
|
||||
PFNGLLINKPROGRAMPROC glLinkProgram;
|
||||
PFNGLUSEPROGRAMPROC glUseProgram;
|
||||
PFNGLISPROGRAMPROC glIsProgram;
|
||||
PFNGLDELETEPROGRAMPROC glDeleteProgram;
|
||||
PFNGLDELETESHADERPROC glDeleteShader;
|
||||
PFNGLGETSHADERIVPROC glGetShaderiv;
|
||||
PFNGLGETPROGRAMIVPROC glGetProgramiv;
|
||||
PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog;
|
||||
PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog;
|
||||
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
|
||||
PFNGLACTIVETEXTUREPROC glActiveTextureProc;
|
||||
PFNGLUNIFORM1FPROC glUniform1f;
|
||||
PFNGLUNIFORM2FPROC glUniform2f;
|
||||
PFNGLUNIFORM1IPROC glUniform1i;
|
||||
PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv;
|
||||
PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffers;
|
||||
PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebuffer;
|
||||
PFNGLFRAMEBUFFERTEXTURE2DEXTPROC glFramebufferTexture;
|
||||
PFNGLGENRENDERBUFFERSEXTPROC glGenRenderbuffers;
|
||||
PFNGLBINDRENDERBUFFEREXTPROC glBindRenderbuffer;
|
||||
PFNGLRENDERBUFFERSTORAGEEXTPROC glRenderbufferStorage;
|
||||
PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC glFramebufferRenderbuffer;
|
||||
PFNGLDRAWBUFFERSPROC glDrawBuffers;
|
||||
PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatus;
|
||||
#else
|
||||
#define glGenFramebuffers glGenFramebuffersEXT
|
||||
#define glBindFramebuffer glBindFramebufferEXT
|
||||
#define glCheckFramebufferStatus glCheckFramebufferStatusEXT
|
||||
#define glActiveTextureProc glActiveTexture
|
||||
#define glFramebufferTexture glFramebufferTexture2DEXT
|
||||
#endif
|
||||
|
||||
GLuint fullscreenShader;
|
||||
GLuint fullscreenFramebuffer = 0;
|
||||
GLuint fullscreenTexture;
|
||||
|
||||
void printShaderInfoLog(GLuint obj, const char* prefix)
|
||||
{
|
||||
int infologLength = 0;
|
||||
int charsWritten = 0;
|
||||
char *infoLog;
|
||||
|
||||
glGetShaderiv(obj, GL_INFO_LOG_LENGTH, &infologLength);
|
||||
|
||||
if (infologLength > 0)
|
||||
{
|
||||
infoLog = (char *)malloc(infologLength);
|
||||
glGetShaderInfoLog(obj, infologLength, &charsWritten, infoLog);
|
||||
fprintf(stdout, "%s: %s\n", prefix, infoLog);
|
||||
free(infoLog);
|
||||
}
|
||||
}
|
||||
void printProgramInfoLog(GLuint obj, const char* prefix)
|
||||
{
|
||||
int infologLength = 0;
|
||||
int charsWritten = 0;
|
||||
char *infoLog;
|
||||
|
||||
glGetProgramiv(obj, GL_INFO_LOG_LENGTH, &infologLength);
|
||||
|
||||
if (infologLength > 0)
|
||||
{
|
||||
infoLog = (char *)malloc(infologLength);
|
||||
glGetProgramInfoLog(obj, infologLength, &charsWritten, infoLog);
|
||||
fprintf(stdout, "%s: %s\n", prefix, infoLog);
|
||||
free(infoLog);
|
||||
}
|
||||
}
|
||||
|
||||
/* This does not have to be very efficient, it is only called when the shader
|
||||
is changed by the user.
|
||||
*/
|
||||
extern bool LoadShaders(int direction, char* shadernameOut) {
|
||||
Video.ShaderIndex += direction;
|
||||
if (direction == 0 && Video.ShaderIndex == -1) {
|
||||
Video.ShaderIndex = 0;
|
||||
}
|
||||
|
||||
GLuint vs, fs;
|
||||
GLint params;
|
||||
fs = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
if (fs == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<FileList> flp;
|
||||
std::string shaderPath(StratagusLibPath);
|
||||
char *cShaderPath;
|
||||
#ifdef _WIN32
|
||||
shaderPath.append("\\shaders\\");
|
||||
int fullpathsize = ExpandEnvironmentStrings(shaderPath.c_str(), NULL, 0);
|
||||
cShaderPath = (char*)calloc(fullpathsize + 1, sizeof(char));
|
||||
ExpandEnvironmentStrings(shaderPath.c_str(), cShaderPath, fullpathsize);
|
||||
#else
|
||||
shaderPath.append("/shaders/");
|
||||
cShaderPath = (char*)shaderPath.c_str();
|
||||
#endif
|
||||
int n = ReadDataDirectory(cShaderPath, flp);
|
||||
int numShaderFiles = 0;
|
||||
int shaderFileToIdx[1024];
|
||||
for (int i = 0; i < n; ++i) {
|
||||
int pos = flp[i].name.find(".glsl");
|
||||
if (pos > 0) {
|
||||
shaderFileToIdx[numShaderFiles] = i;
|
||||
numShaderFiles++;
|
||||
}
|
||||
}
|
||||
if (numShaderFiles <= 0) return false;
|
||||
while (Video.ShaderIndex < 0) {
|
||||
Video.ShaderIndex = numShaderFiles + Video.ShaderIndex;
|
||||
}
|
||||
Video.ShaderIndex = Video.ShaderIndex % numShaderFiles;
|
||||
|
||||
if (shadernameOut) {
|
||||
strncpy(shadernameOut, flp[shaderFileToIdx[Video.ShaderIndex]].name.c_str(), 1023);
|
||||
}
|
||||
shaderPath.append(flp[shaderFileToIdx[Video.ShaderIndex]].name);
|
||||
std::ifstream myfile(shaderPath.c_str());
|
||||
std::string contents((std::istreambuf_iterator<char>(myfile)),
|
||||
std::istreambuf_iterator<char>());
|
||||
myfile.close();
|
||||
|
||||
const char *fragmentSrc[2] = { "#define FRAGMENT\n", contents.c_str() };
|
||||
const char *vertexSrc[2] = { "#define VERTEX\n", contents.c_str() };
|
||||
|
||||
glShaderSource(fs, 2, fragmentSrc, NULL);
|
||||
glCompileShader(fs);
|
||||
glGetShaderiv(fs, GL_COMPILE_STATUS, ¶ms);
|
||||
if (params == GL_FALSE) {
|
||||
printShaderInfoLog(fs, "Fragment Shader");
|
||||
glDeleteShader(fs);
|
||||
return false;
|
||||
}
|
||||
vs = glCreateShader(GL_VERTEX_SHADER);
|
||||
if (fs == 0) {
|
||||
glDeleteShader(fs);
|
||||
return false;
|
||||
}
|
||||
glShaderSource(vs, 2, vertexSrc, NULL);
|
||||
glCompileShader(vs);
|
||||
glGetShaderiv(fs, GL_COMPILE_STATUS, ¶ms);
|
||||
if (params == GL_FALSE) {
|
||||
printShaderInfoLog(vs, "Vertex Shader");
|
||||
glDeleteShader(fs);
|
||||
glDeleteShader(vs);
|
||||
return false;
|
||||
}
|
||||
if (glIsProgram(fullscreenShader)) {
|
||||
glDeleteProgram(fullscreenShader);
|
||||
}
|
||||
fullscreenShader = glCreateProgram();
|
||||
if (fullscreenShader == 0) {
|
||||
glDeleteShader(fs);
|
||||
glDeleteShader(vs);
|
||||
return false;
|
||||
}
|
||||
glAttachShader(fullscreenShader, vs);
|
||||
glAttachShader(fullscreenShader, fs);
|
||||
glLinkProgram(fullscreenShader);
|
||||
glGetProgramiv(fullscreenShader, GL_LINK_STATUS, ¶ms);
|
||||
if (params == GL_FALSE) {
|
||||
printProgramInfoLog(fullscreenShader, "Shader Program");
|
||||
glDeleteShader(fs);
|
||||
glDeleteShader(vs);
|
||||
glDeleteProgram(fullscreenShader);
|
||||
return false;
|
||||
}
|
||||
glDeleteShader(fs);
|
||||
glDeleteShader(vs);
|
||||
return true;
|
||||
}
|
||||
|
||||
extern bool LoadShaderExtensions() {
|
||||
#ifndef __APPLE__
|
||||
glCreateShader = (PFNGLCREATESHADERPROC)(uintptr_t)SDL_GL_GetProcAddress("glCreateShader");
|
||||
glShaderSource = (PFNGLSHADERSOURCEPROC)(uintptr_t)SDL_GL_GetProcAddress("glShaderSource");
|
||||
glCompileShader = (PFNGLCOMPILESHADERPROC)(uintptr_t)SDL_GL_GetProcAddress("glCompileShader");
|
||||
glCreateProgram = (PFNGLCREATEPROGRAMPROC)(uintptr_t)SDL_GL_GetProcAddress("glCreateProgram");
|
||||
glAttachShader = (PFNGLATTACHSHADERPROC)(uintptr_t)SDL_GL_GetProcAddress("glAttachShader");
|
||||
glLinkProgram = (PFNGLLINKPROGRAMPROC)(uintptr_t)SDL_GL_GetProcAddress("glLinkProgram");
|
||||
glUseProgram = (PFNGLUSEPROGRAMPROC)(uintptr_t)SDL_GL_GetProcAddress("glUseProgram");
|
||||
glGetShaderiv = (PFNGLGETSHADERIVPROC)(uintptr_t)SDL_GL_GetProcAddress("glGetShaderiv");
|
||||
glGetProgramiv = (PFNGLGETPROGRAMIVPROC)(uintptr_t)SDL_GL_GetProcAddress("glGetProgramiv");
|
||||
glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC)(uintptr_t)SDL_GL_GetProcAddress("glGetShaderInfoLog");
|
||||
glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC)(uintptr_t)SDL_GL_GetProcAddress("glGetProgramInfoLog");
|
||||
glIsProgram = (PFNGLISPROGRAMPROC)(uintptr_t)SDL_GL_GetProcAddress("glIsProgram");
|
||||
glDeleteProgram = (PFNGLDELETEPROGRAMPROC)(uintptr_t)SDL_GL_GetProcAddress("glDeleteProgram");
|
||||
glDeleteShader = (PFNGLDELETESHADERPROC)(uintptr_t)SDL_GL_GetProcAddress("glDeleteShader");
|
||||
|
||||
glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC)(uintptr_t)SDL_GL_GetProcAddress("glGetUniformLocation");
|
||||
glActiveTextureProc = (PFNGLACTIVETEXTUREPROC)(uintptr_t)SDL_GL_GetProcAddress("glActiveTexture");
|
||||
glUniform1f = (PFNGLUNIFORM1FPROC)(uintptr_t)SDL_GL_GetProcAddress("glUniform1f");
|
||||
glUniform2f = (PFNGLUNIFORM2FPROC)(uintptr_t)SDL_GL_GetProcAddress("glUniform2f");
|
||||
glUniform1i = (PFNGLUNIFORM1IPROC)(uintptr_t)SDL_GL_GetProcAddress("glUniform1i");
|
||||
glUniformMatrix4fv = (PFNGLUNIFORMMATRIX4FVPROC)(uintptr_t)SDL_GL_GetProcAddress("glUniformMatrix4fv");
|
||||
|
||||
glGenFramebuffers = (PFNGLGENFRAMEBUFFERSEXTPROC)(uintptr_t)SDL_GL_GetProcAddress("glGenFramebuffers");
|
||||
glBindFramebuffer = (PFNGLBINDFRAMEBUFFEREXTPROC)(uintptr_t)SDL_GL_GetProcAddress("glBindFramebuffer");
|
||||
glFramebufferTexture = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC)(uintptr_t)SDL_GL_GetProcAddress("glFramebufferTexture2D");
|
||||
glGenRenderbuffers = (PFNGLGENRENDERBUFFERSEXTPROC)(uintptr_t)SDL_GL_GetProcAddress("glGenRenderbuffers");
|
||||
glBindRenderbuffer = (PFNGLBINDRENDERBUFFEREXTPROC)(uintptr_t)SDL_GL_GetProcAddress("glBindRenderbuffer");
|
||||
glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEEXTPROC)(uintptr_t)SDL_GL_GetProcAddress("glRenderbufferStorage");
|
||||
glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC)(uintptr_t)SDL_GL_GetProcAddress("glFramebufferRenderbuffer");
|
||||
glDrawBuffers = (PFNGLDRAWBUFFERSPROC)(uintptr_t)SDL_GL_GetProcAddress("glDrawBuffers");
|
||||
glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC)(uintptr_t)SDL_GL_GetProcAddress("glCheckFramebufferStatus");
|
||||
if (glCreateShader && glGenFramebuffers && glGetUniformLocation && glActiveTextureProc) {
|
||||
return LoadShaders(0, NULL);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
return false; // FIXME: Does not currently work on OSX
|
||||
#endif
|
||||
}
|
||||
|
||||
extern void SetupFramebuffer() {
|
||||
glGenTextures(1, &fullscreenTexture); // generate a texture to render to off-screen
|
||||
glBindTexture(GL_TEXTURE_2D, fullscreenTexture); // bind it, so all texture functions go to it
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Video.ViewportWidth, Video.ViewportHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); // give an empty image to opengl
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // make sure we use nearest filtering
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glGenFramebuffers(1, &fullscreenFramebuffer); // generate a framebuffer to render to
|
||||
glBindFramebuffer(GL_FRAMEBUFFER_EXT, fullscreenFramebuffer); // bind it
|
||||
glFramebufferTexture(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fullscreenTexture, 0); // set our texture as the "screen" of the framebuffer
|
||||
GLenum DrawBuffers[1] = { GL_COLOR_ATTACHMENT0_EXT };
|
||||
glDrawBuffers(1, DrawBuffers);
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT) {
|
||||
fprintf(stderr, "FATAL: Error Creating Framebuffer! Try running without OpenGL.");
|
||||
exit(-1);
|
||||
}
|
||||
glBindFramebuffer(GL_FRAMEBUFFER_EXT, fullscreenFramebuffer);
|
||||
}
|
||||
|
||||
extern void RenderFramebufferToScreen() {
|
||||
// switch the rendering target back to the real display
|
||||
glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
|
||||
// setup our shader program
|
||||
glUseProgram(fullscreenShader);
|
||||
|
||||
// These are the default uniforms for glsl converted libretro shaders
|
||||
GLint Texture = glGetUniformLocation(fullscreenShader, "Texture");
|
||||
GLint MVPMatrix = glGetUniformLocation(fullscreenShader, "MVPMatrix");
|
||||
GLint FrameDirection = glGetUniformLocation(fullscreenShader, "FrameDirection");
|
||||
GLint FrameCount = glGetUniformLocation(fullscreenShader, "FrameCount");
|
||||
GLint OutputSize = glGetUniformLocation(fullscreenShader, "OutputSize");
|
||||
GLint TextureSize = glGetUniformLocation(fullscreenShader, "TextureSize");
|
||||
GLint InputSize = glGetUniformLocation(fullscreenShader, "InputSize");
|
||||
|
||||
glUniform1i(Texture, 0);
|
||||
GLfloat matrix[4 * 4];
|
||||
glGetFloatv(GL_MODELVIEW_MATRIX, matrix);
|
||||
glUniformMatrix4fv(MVPMatrix, 1, GL_FALSE, matrix);
|
||||
glUniform1f(FrameDirection, 1);
|
||||
glUniform1f(FrameCount, 1);
|
||||
glUniform2f(OutputSize, (float)Video.ViewportWidth, (float)Video.ViewportHeight);
|
||||
glUniform2f(TextureSize, (float)Video.ViewportWidth, (float)Video.ViewportHeight);
|
||||
glUniform2f(InputSize, (float)Video.Width, (float)Video.Height);
|
||||
|
||||
float widthRel = (float)Video.Width / Video.ViewportWidth;
|
||||
float heightRel = (float)Video.Height / Video.ViewportHeight;
|
||||
|
||||
glActiveTextureProc(GL_TEXTURE0);
|
||||
// render the framebuffer texture to a fullscreen quad on the real display
|
||||
glBindTexture(GL_TEXTURE_2D, fullscreenTexture);
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex2i(0, 0);
|
||||
glTexCoord2f(widthRel, 1);
|
||||
glVertex2i(Video.ViewportWidth, 0);
|
||||
glTexCoord2f(widthRel, 1 - heightRel);
|
||||
glVertex2i(Video.ViewportWidth, Video.ViewportHeight);
|
||||
glTexCoord2f(0, 1 - heightRel);
|
||||
glVertex2i(0, Video.ViewportHeight);
|
||||
glEnd();
|
||||
SDL_GL_SwapBuffers();
|
||||
glUseProgram(0); // Disable shaders again, and render to framebuffer again
|
||||
glBindFramebuffer(GL_FRAMEBUFFER_EXT, fullscreenFramebuffer);
|
||||
}
|
||||
#endif
|
|
@ -1,229 +0,0 @@
|
|||
// _________ __ __
|
||||
// / _____// |_____________ _/ |______ ____ __ __ ______
|
||||
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
|
||||
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
|
||||
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
||||
// \/ \/ \//_____/ \/
|
||||
// ______________________ ______________________
|
||||
// T H E W A R B E G I N S
|
||||
// Stratagus - A free fantasy real time strategy game engine
|
||||
//
|
||||
/**@name sprite.cpp - The general sprite functions. */
|
||||
//
|
||||
// (c) Copyright 2000-2011 by Lutz Sammer, Stephan Rasenberg,
|
||||
// Nehal Mistry, Jimmy Salmon and Pali Rohár
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; only version 2 of the License.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
// 02111-1307, USA.
|
||||
//
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
|
||||
//@{
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Includes
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "stratagus.h"
|
||||
#include "video.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Functions
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/** Draw a rectangular part of a CGraphic to the screen.
|
||||
**
|
||||
** This function does not attempt to clip the CGraphic based on the
|
||||
** screen coordinates. If the caller wants clipping, it can set the
|
||||
** parameters accordingly, or perhaps configure OpenGL to clip the
|
||||
** output.
|
||||
**
|
||||
** @param g
|
||||
** The graphic to be drawn. It may consist of multiple
|
||||
** OpenGL textures if it is too large to fit in one texture.
|
||||
** @param textures
|
||||
** The OpenGL textures to be drawn. There must be g->NumTextures
|
||||
** elements in the array. These textures may be the same as
|
||||
** g->Textures, or perhaps variants of them with different colors
|
||||
** for a specific player.
|
||||
** @param gx_beg
|
||||
** X coordinate of the left side of the rectangle to be drawn from @a *g.
|
||||
** @param gy_beg
|
||||
** Y coordinate of the top of the rectangle to be drawn from @a *g.
|
||||
** @param gx_end
|
||||
** X coordinate of the right side of the rectangle to be drawn from @a *g.
|
||||
** @param gy_end
|
||||
** Y coordinate of the bottom of the rectangle to be drawn from @a *g.
|
||||
** @param sx_beg
|
||||
** X coordinate of the left side of the graphic on the screen.
|
||||
** @param sy_beg
|
||||
** Y coordinate of the top of the graphic on the screen.
|
||||
** @param flip
|
||||
** Whether to flip the graphic in the X direction.
|
||||
** In any case, the graphic will extend from @a sx_beg
|
||||
** to (@a gx_end - @a gx_beg + @a sx_beg) on the screen.
|
||||
** Flipping controls which of those values corresponds
|
||||
** to @a gx_beg and which one to @a gx_end.
|
||||
*/
|
||||
void DrawTexture(const CGraphic *g, GLuint *textures,
|
||||
int gx_beg, int gy_beg, int gx_end, int gy_end,
|
||||
int sx_beg, int sy_beg, int flip)
|
||||
{
|
||||
// gx and gy coordinates count pixels from the top left corner
|
||||
// of the CGraphic, which can span multiple textures.
|
||||
// tx and ty coordinates are in an individual texture,
|
||||
// as GLfloats between 0.0 and 1.0, like OpenGL requires.
|
||||
// sx and sy coordinates are on the screen. This function does not
|
||||
// know what the origin is there.
|
||||
|
||||
Assert(0 <= gx_beg);
|
||||
Assert(0 <= gy_beg);
|
||||
Assert(gx_beg <= gx_end); // draws nothing if equal
|
||||
Assert(gy_beg <= gy_end); // draws nothing if equal
|
||||
Assert(gx_end <= g->GraphicWidth);
|
||||
Assert(gy_end <= g->GraphicHeight);
|
||||
|
||||
for (int tex_gy_beg = gy_beg / GLMaxTextureSize * GLMaxTextureSize;;
|
||||
tex_gy_beg += GLMaxTextureSize) {
|
||||
int tex_gy_end = tex_gy_beg + GLMaxTextureSize;
|
||||
int clip_gy_beg = std::max<int>(gy_beg, tex_gy_beg);
|
||||
int clip_gy_end = std::min<int>(gy_end, tex_gy_end);
|
||||
if (clip_gy_beg >= clip_gy_end) {
|
||||
break;
|
||||
}
|
||||
|
||||
int clip_sy_beg = clip_gy_beg - gy_beg + sy_beg;
|
||||
int clip_sy_end = clip_gy_end - gy_beg + sy_beg;
|
||||
Assert(clip_sy_end != clip_sy_beg);
|
||||
Assert(abs(clip_sy_end - clip_sy_beg) <= g->GraphicHeight);
|
||||
|
||||
GLfloat clip_ty_beg, clip_ty_end;
|
||||
if (tex_gy_end >= g->GraphicHeight) {
|
||||
// This is the last row of textures in
|
||||
// the Y direction. These textures may
|
||||
// be smaller than the ones at the top.
|
||||
clip_ty_beg = (clip_gy_beg - tex_gy_beg)
|
||||
* g->TextureHeight
|
||||
/ (g->GraphicHeight - tex_gy_beg);
|
||||
clip_ty_end = (clip_gy_end - tex_gy_beg)
|
||||
* g->TextureHeight
|
||||
/ (g->GraphicHeight - tex_gy_beg);
|
||||
} else {
|
||||
clip_ty_beg = (clip_gy_beg - tex_gy_beg)
|
||||
/ GLfloat(GLMaxTextureSize);
|
||||
clip_ty_end = (clip_gy_end - tex_gy_beg)
|
||||
/ GLfloat(GLMaxTextureSize);
|
||||
}
|
||||
Assert(0.0f <= clip_ty_beg);
|
||||
Assert(clip_ty_beg < clip_ty_end);
|
||||
Assert(clip_ty_end <= 1.0f);
|
||||
|
||||
for (int tex_gx_beg = gx_beg / GLMaxTextureSize * GLMaxTextureSize;;
|
||||
tex_gx_beg += GLMaxTextureSize) {
|
||||
int tex_gx_end = tex_gx_beg + GLMaxTextureSize;
|
||||
int clip_gx_beg = std::max<int>(gx_beg, tex_gx_beg);
|
||||
int clip_gx_end = std::min<int>(gx_end, tex_gx_end);
|
||||
if (clip_gx_beg >= clip_gx_end) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Flipping does not change which parts of the
|
||||
// CGraphic get drawn. It only changes where
|
||||
// they get drawn.
|
||||
int clip_sx_beg, clip_sx_end;
|
||||
if (flip) {
|
||||
clip_sx_beg = sx_beg + (gx_end - clip_gx_beg);
|
||||
clip_sx_end = sx_beg + (gx_end - clip_gx_end);
|
||||
} else {
|
||||
clip_sx_beg = sx_beg + (clip_gx_beg - gx_beg);
|
||||
clip_sx_end = sx_beg + (clip_gx_end - gx_beg);
|
||||
}
|
||||
Assert(clip_sx_end != clip_sx_beg);
|
||||
Assert(abs(clip_sx_end - clip_sx_beg) <= g->GraphicWidth);
|
||||
|
||||
GLfloat clip_tx_beg, clip_tx_end;
|
||||
if (tex_gx_end >= g->GraphicWidth) {
|
||||
// This is the last column of textures in
|
||||
// the X direction. These textures may
|
||||
// be smaller than the ones at the left.
|
||||
clip_tx_beg = (clip_gx_beg - tex_gx_beg)
|
||||
* g->TextureWidth
|
||||
/ (g->GraphicWidth - tex_gx_beg);
|
||||
clip_tx_end = (clip_gx_end - tex_gx_beg)
|
||||
* g->TextureWidth
|
||||
/ (g->GraphicWidth - tex_gx_beg);
|
||||
} else {
|
||||
clip_tx_beg = (clip_gx_beg - tex_gx_beg)
|
||||
/ GLfloat(GLMaxTextureSize);
|
||||
clip_tx_end = (clip_gx_end - tex_gx_beg)
|
||||
/ GLfloat(GLMaxTextureSize);
|
||||
}
|
||||
Assert(0.0f <= clip_tx_beg);
|
||||
Assert(clip_tx_beg < clip_tx_end);
|
||||
Assert(clip_tx_end <= 1.0f);
|
||||
|
||||
int texture = tex_gy_beg / GLMaxTextureSize
|
||||
* ((g->GraphicWidth - 1) / GLMaxTextureSize + 1)
|
||||
+ tex_gx_beg / GLMaxTextureSize;
|
||||
Assert(texture >= 0 && texture < g->NumTextures);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, textures[texture]);
|
||||
|
||||
#ifdef USE_GLES
|
||||
float texCoord[] = {
|
||||
clip_tx_beg, clip_ty_beg,
|
||||
clip_tx_end, clip_ty_beg,
|
||||
clip_tx_beg, clip_ty_end,
|
||||
clip_tx_end, clip_ty_end
|
||||
};
|
||||
|
||||
float vertex[] = {
|
||||
2.0f / (GLfloat)Video.Width *clip_sx_beg - 1.0f, -2.0f / (GLfloat)Video.Height *clip_sy_beg + 1.0f,
|
||||
2.0f / (GLfloat)Video.Width *clip_sx_end - 1.0f, -2.0f / (GLfloat)Video.Height *clip_sy_beg + 1.0f,
|
||||
2.0f / (GLfloat)Video.Width *clip_sx_beg - 1.0f, -2.0f / (GLfloat)Video.Height *clip_sy_end + 1.0f,
|
||||
2.0f / (GLfloat)Video.Width *clip_sx_end - 1.0f, -2.0f / (GLfloat)Video.Height *clip_sy_end + 1.0f
|
||||
};
|
||||
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, texCoord);
|
||||
glVertexPointer(2, GL_FLOAT, 0, vertex);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
#endif
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(clip_tx_beg, clip_ty_beg);
|
||||
glVertex2i(clip_sx_beg, clip_sy_beg);
|
||||
glTexCoord2f(clip_tx_beg, clip_ty_end);
|
||||
glVertex2i(clip_sx_beg, clip_sy_end);
|
||||
glTexCoord2f(clip_tx_end, clip_ty_end);
|
||||
glVertex2i(clip_sx_end, clip_sy_end);
|
||||
glTexCoord2f(clip_tx_end, clip_ty_beg);
|
||||
glVertex2i(clip_sx_end, clip_sy_beg);
|
||||
glEnd();
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//@}
|
||||
|
||||
#endif
|
|
@ -155,13 +155,6 @@ extern void SdlUnlockScreen(); /// Do SDL hardware unlock
|
|||
CVideo Video;
|
||||
/*static*/ CColorCycling *CColorCycling::s_instance = NULL;
|
||||
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
char ForceUseOpenGL;
|
||||
bool UseOpenGL; /// Use OpenGL
|
||||
bool ZoomNoResize;
|
||||
bool GLShaderPipelineSupported = true;
|
||||
#endif
|
||||
|
||||
char VideoForceFullScreen; /// fullscreen set from commandline
|
||||
|
||||
double NextFrameTicks; /// Ticks of begin of the next frame
|
||||
|
@ -274,32 +267,9 @@ void CVideo::ClearScreen()
|
|||
bool CVideo::ResizeScreen(int w, int h)
|
||||
{
|
||||
if (VideoValidResolution(w, h)) {
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
FreeOpenGLGraphics();
|
||||
FreeOpenGLFonts();
|
||||
UI.Minimap.FreeOpenGL();
|
||||
}
|
||||
#endif
|
||||
SDL_SetWindowSize(TheWindow, w, h);
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
ViewportWidth = w;
|
||||
ViewportHeight = h;
|
||||
if (ZoomNoResize) {
|
||||
ReloadOpenGL();
|
||||
} else {
|
||||
Width = w;
|
||||
Height = h;
|
||||
SetClipping(0, 0, Video.Width - 1, Video.Height - 1);
|
||||
if (UseOpenGL) {
|
||||
ReloadOpenGL();
|
||||
}
|
||||
}
|
||||
#else
|
||||
Width = w;
|
||||
Height = h;
|
||||
SetClipping(0, 0, Video.Width - 1, Video.Height - 1);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -394,12 +364,6 @@ void AddColorCyclingRange(unsigned int begin, unsigned int end)
|
|||
|
||||
void SetColorCycleAll(bool value)
|
||||
{
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
// FIXME: In OpenGL-mode, we can only cycle the tileset graphic
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
CColorCycling::GetInstance().ColorCycleAll = value;
|
||||
}
|
||||
|
||||
|
@ -464,15 +428,7 @@ void ColorCycle()
|
|||
}
|
||||
} else if (Map.TileGraphic->Surface->format->BytesPerPixel == 1) {
|
||||
++colorCycling.cycleCount;
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL && colorCycling.ColorIndexRanges.size() > 0) {
|
||||
LazilyMakeColorCyclingTextures(Map.TileGraphic, colorCycling.ColorIndexRanges);
|
||||
Map.TileGraphic->Textures = Map.TileGraphic->ColorCyclingTextures[colorCycling.cycleCount % Map.TileGraphic->NumColorCycles];
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
ColorCycleSurface(*Map.TileGraphic->Surface);
|
||||
}
|
||||
ColorCycleSurface(*Map.TileGraphic->Surface);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -486,16 +442,7 @@ void RestoreColorCyclingSurface()
|
|||
ColorCycleSurface_Reverse(*surface, colorCycling.cycleCount);
|
||||
}
|
||||
} else if (Map.TileGraphic->Surface->format->BytesPerPixel == 1) {
|
||||
#if defined(USE_OPENGL) || defined(USE_GLES)
|
||||
if (UseOpenGL) {
|
||||
LazilyMakeColorCyclingTextures(Map.TileGraphic, colorCycling.ColorIndexRanges);
|
||||
Map.TileGraphic->Textures = Map.TileGraphic->ColorCyclingTextures[0];
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
ColorCycleSurface_Reverse(*Map.TileGraphic->Surface, colorCycling.cycleCount);
|
||||
}
|
||||
ColorCycleSurface_Reverse(*Map.TileGraphic->Surface, colorCycling.cycleCount);
|
||||
}
|
||||
colorCycling.cycleCount = 0;
|
||||
}
|
||||
|
|
|
@ -217,11 +217,6 @@ Section "${NAME}"
|
|||
File "${EXE}"
|
||||
File "${SDL}"
|
||||
File "${LUADLL}"
|
||||
!ifdef FLUID
|
||||
File "${FLUIDDLL}"
|
||||
File "${GLIBDLL}"
|
||||
File "${GTHREADDLL}"
|
||||
!endif
|
||||
WriteRegStr HKLM "${REGKEY}" "DisplayName" "${NAME}"
|
||||
WriteRegStr HKLM "${REGKEY}" "UninstallString" "$\"$INSTDIR\${UNINSTALL}$\""
|
||||
WriteRegStr HKLM "${REGKEY}" "QuietUninstallString" "$\"$INSTDIR\${UNINSTALL}$\" /S"
|
||||
|
|
Loading…
Add table
Reference in a new issue