From 967c385d8b17f1550cb179b6fc48535b92618c97 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Sat, 8 Dec 2018 13:50:50 +0800 Subject: [PATCH] =?UTF-8?q?tga=E8=A7=A3=E6=99=B0=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E7=BF=BB=E8=BD=AC=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/DirectGLTexture/TGATexture.cpp | 28 +++++++++++++++++++++++++- example/DirectGLTexture/main.cpp | 8 ++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/example/DirectGLTexture/TGATexture.cpp b/example/DirectGLTexture/TGATexture.cpp index c131c88b..cf3b0c50 100644 --- a/example/DirectGLTexture/TGATexture.cpp +++ b/example/DirectGLTexture/TGATexture.cpp @@ -69,6 +69,7 @@ namespace hgl uint videomemory_format; uint source_format; + uint line_size=0; if(header->image_type==2) { @@ -76,17 +77,20 @@ namespace hgl { videomemory_format=GL_RGB8; source_format=GL_BGR; + line_size=header->width*3; } else if(header->bit==32) { videomemory_format=GL_RGBA8; source_format=GL_BGRA; + line_size=header->width*4; } } else if(header->image_type==3&&header->bit==8) { videomemory_format=GL_R8; source_format=GL_RED; + line_size=header->width; } else { @@ -98,7 +102,29 @@ namespace hgl glCreateTextures(GL_TEXTURE_2D,1,&tex_id); glTextureStorage2D(tex_id,1,videomemory_format,header->width,header->height); - glTextureSubImage2D(tex_id,0,0,0,header->width,header->height,source_format,GL_UNSIGNED_BYTE,data+sizeof(TGAHeader)); + + TGAImageDesc img_desc; + + img_desc.image_desc=header->image_desc; + + if(img_desc.direction==1) + glTextureSubImage2D(tex_id,0,0,0,header->width,header->height,source_format,GL_UNSIGNED_BYTE,data+sizeof(TGAHeader)); + else + { + char *new_img=new char[line_size*header->height]; + char *sp=data+sizeof(TGAHeader)+line_size*(header->height-1); + char *tp=new_img; + + for(int i=0;iheight;i++) + { + memcpy(tp,sp,line_size); + tp+=line_size; + sp-=line_size; + } + + glTextureSubImage2D(tex_id,0,0,0,header->width,header->height,source_format,GL_UNSIGNED_BYTE,new_img); + delete[] new_img; + } glTextureParameteri(tex_id,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTextureParameteri(tex_id,GL_TEXTURE_MAG_FILTER,GL_LINEAR); diff --git a/example/DirectGLTexture/main.cpp b/example/DirectGLTexture/main.cpp index 2da98c1c..f9e5e1de 100644 --- a/example/DirectGLTexture/main.cpp +++ b/example/DirectGLTexture/main.cpp @@ -74,10 +74,10 @@ VB2f *vb_vertex=nullptr; VB2f *vb_texcoord=nullptr; VertexArray *va=nullptr; -constexpr float vertex_data[]={ -0.5f, 0.5f, - -0.5f,-0.5f, - 0.5f, 0.5f, - 0.5f,-0.5f +constexpr float vertex_data[]={ -0.75f, 0.75f, + -0.75f,-0.75f, + 0.75f, 0.75f, + 0.75f,-0.75f }; constexpr float texcoord_data[]={ 0,0,