summaryrefslogtreecommitdiffstats
path: root/src/graphics/opengl
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2012-07-16 19:17:26 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2012-07-16 19:17:26 +0200
commit68a7bafe37adef0e5ef12c2d0e8461a21e05363b (patch)
treef0185e459ea0c5638fca7bada5f2e440fd9eda51 /src/graphics/opengl
parent54f4da87923465a5387e2e854b58616647deb7af (diff)
downloadcolobot-68a7bafe37adef0e5ef12c2d0e8461a21e05363b.tar.gz
colobot-68a7bafe37adef0e5ef12c2d0e8461a21e05363b.tar.bz2
colobot-68a7bafe37adef0e5ef12c2d0e8461a21e05363b.zip
Fixes in texture loading
- added other texture formats: BGR and BGRA - fixed texture loading in model viewer - moved code from texture.cpp module to texture.h
Diffstat (limited to 'src/graphics/opengl')
-rw-r--r--src/graphics/opengl/gldevice.cpp10
-rw-r--r--src/graphics/opengl/test/CMakeLists.txt6
-rw-r--r--src/graphics/opengl/test/model_test.cpp5
-rw-r--r--src/graphics/opengl/test/texture_test.cpp4
4 files changed, 18 insertions, 7 deletions
diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp
index eb4eb31..e329ff4 100644
--- a/src/graphics/opengl/gldevice.cpp
+++ b/src/graphics/opengl/gldevice.cpp
@@ -393,10 +393,16 @@ Gfx::Texture* Gfx::CGLDevice::CreateTexture(CImage *image, const Gfx::TextureCre
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE);
GLenum sourceFormat = 0;
- if (params.alpha)
+ if (params.format == Gfx::TEX_IMG_RGB)
+ sourceFormat = GL_RGB;
+ else if (params.format == Gfx::TEX_IMG_BGR)
+ sourceFormat = GL_BGR;
+ else if (params.format == Gfx::TEX_IMG_RGBA)
sourceFormat = GL_RGBA;
+ else if (params.format == Gfx::TEX_IMG_BGRA)
+ sourceFormat = GL_BGRA;
else
- sourceFormat = GL_RGB;
+ assert(false);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, data->surface->w, data->surface->h,
0, sourceFormat, GL_UNSIGNED_BYTE, data->surface->pixels);
diff --git a/src/graphics/opengl/test/CMakeLists.txt b/src/graphics/opengl/test/CMakeLists.txt
index 36bd738..4242c77 100644
--- a/src/graphics/opengl/test/CMakeLists.txt
+++ b/src/graphics/opengl/test/CMakeLists.txt
@@ -8,6 +8,8 @@ find_package(PNG REQUIRED)
set(CMAKE_BUILD_TYPE debug)
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -O0")
+set(ADD_LIBS "")
+
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(PLATFORM_WINDOWS 1)
set(PLATFORM_LINUX 0)
@@ -16,6 +18,7 @@ elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(PLATFORM_WINDOWS 0)
set(PLATFORM_LINUX 1)
set(PLATFORM_OTHER 0)
+ set(ADD_LIBS "-lrt")
else()
set(PLATFORM_WINDOWS 0)
set(PLATFORM_LINUX 0)
@@ -28,7 +31,6 @@ configure_file(../../../common/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/common
set(TEXTURE_SOURCES
../gldevice.cpp
../../common/device.cpp
-../../common/texture.cpp
../../../common/logger.cpp
../../../common/image.cpp
texture_test.cpp
@@ -38,7 +40,6 @@ set(MODEL_SOURCES
../gldevice.cpp
../../common/device.cpp
../../common/modelfile.cpp
-../../common/texture.cpp
../../../common/logger.cpp
../../../common/image.cpp
../../../common/iman.cpp
@@ -54,6 +55,7 @@ ${SDL_LIBRARY}
${SDLIMAGE_LIBRARY}
${OPENGL_LIBRARY}
${PNG_LIBRARIES}
+${ADD_LIBS}
)
add_executable(texture_test ${TEXTURE_SOURCES})
diff --git a/src/graphics/opengl/test/model_test.cpp b/src/graphics/opengl/test/model_test.cpp
index b73dc71..88404b7 100644
--- a/src/graphics/opengl/test/model_test.cpp
+++ b/src/graphics/opengl/test/model_test.cpp
@@ -66,8 +66,11 @@ void LoadTexture(Gfx::CGLDevice *device, const std::string &name)
else
{
Gfx::TextureCreateParams texCreateParams;
- texCreateParams.alpha = false;
texCreateParams.mipmap = true;
+ if (img.GetData()->surface->format->Amask == 0)
+ texCreateParams.format = Gfx::TEX_IMG_BGR;
+ else
+ texCreateParams.format = Gfx::TEX_IMG_BGRA;
texCreateParams.minFilter = Gfx::TEX_MIN_FILTER_LINEAR_MIPMAP_LINEAR;
texCreateParams.magFilter = Gfx::TEX_MAG_FILTER_LINEAR;
texCreateParams.wrapT = Gfx::TEX_WRAP_CLAMP;
diff --git a/src/graphics/opengl/test/texture_test.cpp b/src/graphics/opengl/test/texture_test.cpp
index 79518f8..03847fc 100644
--- a/src/graphics/opengl/test/texture_test.cpp
+++ b/src/graphics/opengl/test/texture_test.cpp
@@ -27,15 +27,15 @@ void Init(Gfx::CGLDevice *device)
}
Gfx::TextureCreateParams tex1CreateParams;
- tex1CreateParams.alpha = true;
tex1CreateParams.mipmap = true;
+ tex1CreateParams.format = Gfx::TEX_IMG_RGBA;
tex1CreateParams.minFilter = Gfx::TEX_MIN_FILTER_LINEAR_MIPMAP_LINEAR;
tex1CreateParams.magFilter = Gfx::TEX_MAG_FILTER_LINEAR;
tex1CreateParams.wrapT = Gfx::TEX_WRAP_CLAMP;
Gfx::TextureCreateParams tex2CreateParams;
- tex2CreateParams.alpha = true;
tex2CreateParams.mipmap = true;
+ tex2CreateParams.format = Gfx::TEX_IMG_RGBA;
tex2CreateParams.minFilter = Gfx::TEX_MIN_FILTER_NEAREST_MIPMAP_NEAREST;
tex2CreateParams.magFilter = Gfx::TEX_MAG_FILTER_NEAREST;
tex2CreateParams.wrapS = Gfx::TEX_WRAP_CLAMP;