|
From: julien r. <jul...@us...> - 2004-09-27 21:34:21
|
Update of /cvsroot/epfl/tgengine-0.1 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14486 Modified Files: Makefile Makefile.Linux Makefile.OSX d3map.cc defs.h glrenderer.cc glrenderernv15.cc texture.cc texture.h Log Message: chargement png et jpg affichage fps divers fix Index: Makefile =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/Makefile,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Makefile 27 Sep 2004 20:57:52 -0000 1.5 --- Makefile 27 Sep 2004 21:34:05 -0000 1.6 *************** *** 13,16 **** --- 13,17 ---- make -f Makefile.Linux + linuxDebug: make -f Makefile.Linux "CFLAGS = -ggdb -DDEBUG -DTGLINUX" Index: d3map.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/d3map.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** d3map.cc 27 Sep 2004 19:33:58 -0000 1.3 --- d3map.cc 27 Sep 2004 21:34:05 -0000 1.4 *************** *** 7,12 **** { FILE* fp = NULL; ! char* buffer; ! size_t size; numAreas = 0; --- 7,12 ---- { FILE* fp = NULL; ! char* buffer=NULL; ! // size_t size; numAreas = 0; *************** *** 41,43 **** ! } \ No newline at end of file --- 41,44 ---- ! } ! Index: defs.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/defs.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** defs.h 26 Sep 2004 13:15:06 -0000 1.1.1.1 --- defs.h 27 Sep 2004 21:34:05 -0000 1.2 *************** *** 15,18 **** --- 15,20 ---- { + #define TGSDL_IMAGE + #define SWAPFLOAT(name) name=Engine::pEndian->Float(name); #define SWAPLONG(name) name=Engine::pEndian->Long(name); Index: glrenderer.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/glrenderer.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** glrenderer.cc 27 Sep 2004 14:45:59 -0000 1.4 --- glrenderer.cc 27 Sep 2004 21:34:05 -0000 1.5 *************** *** 63,67 **** pDefaultFont = new Font(); ! LoadFont(pDefaultFont, "data/font.bmp"); bWireFrame = false; --- 63,67 ---- pDefaultFont = new Font(); ! LoadFont(pDefaultFont, "data/font.png"); bWireFrame = false; *************** *** 428,437 **** glEnable(GL_DEPTH_TEST); ! Begin2D(); ! RenderText(pDefaultFont, "X = rouge", 10, 0, 0.6); ! RenderText(pDefaultFont, "Y = vert", 10, 15, 0.6); ! RenderText(pDefaultFont, "Z = bleu", 10, 30, 0.6); ! End2D(); } --- 428,438 ---- glEnable(GL_DEPTH_TEST); ! char fps[50]; Begin2D(); ! RenderText(NULL, "X = rouge", 10, 0, 0.6); ! RenderText(NULL, "Y = vert", 10, 15, 0.6); ! RenderText(NULL, "Z = bleu", 10, 30, 0.6); ! sprintf (fps, "fps %.0f", Engine::pEngine->GetTimer()->GetFPS()); ! RenderText(NULL, fps, 10, 50, 0.6); End2D(); } Index: Makefile.Linux =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/Makefile.Linux,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Makefile.Linux 27 Sep 2004 20:35:00 -0000 1.2 --- Makefile.Linux 27 Sep 2004 21:34:05 -0000 1.3 *************** *** 6,10 **** OBJSRC = $(wildcard *.cc) OBJS = $(addsuffix .${OBJ_EXT}, $(basename $(OBJSRC))) ! CFLAGS = -DTGLINUX -O3 CC = g++ --- 6,10 ---- OBJSRC = $(wildcard *.cc) OBJS = $(addsuffix .${OBJ_EXT}, $(basename $(OBJSRC))) ! CFLAGS = -DTGLINUX -O3 -DDEBUG CC = g++ Index: Makefile.OSX =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/Makefile.OSX,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Makefile.OSX 27 Sep 2004 20:35:00 -0000 1.2 --- Makefile.OSX 27 Sep 2004 21:34:05 -0000 1.3 *************** *** 6,10 **** OBJSRC = $(wildcard *.cc) OBJS = $(addsuffix .${OBJ_EXT}, $(basename $(OBJSRC))) ! CFLAGS = -DTGOSX -O3 CC = g++ --- 6,10 ---- OBJSRC = $(wildcard *.cc) OBJS = $(addsuffix .${OBJ_EXT}, $(basename $(OBJSRC))) ! CFLAGS = -DTGOSX -O3 -DDEBUG CC = g++ Index: texture.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/texture.cc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** texture.cc 27 Sep 2004 19:33:58 -0000 1.2 --- texture.cc 27 Sep 2004 21:34:05 -0000 1.3 *************** *** 10,14 **** #endif #include "engine.h" ! namespace tg --- 10,14 ---- #endif #include "engine.h" ! #include "SDL/SDL_image.h" namespace tg *************** *** 33,37 **** glDeleteTextures (1, &iId); ! return LoadBMP (image, type); } --- 33,47 ---- glDeleteTextures (1, &iId); ! if (strstr(image, ".bmp") != NULL) ! return LoadBMP (image, type); ! if (strstr(image, ".tga") != NULL) ! #ifdef TGSDL_IMAGE ! return LoadTGA (image, type); ! if (strstr(image, ".png") != NULL) ! return LoadPNG (image, type); ! if (strstr(image, ".jpeg") != NULL || strstr(image, ".jpg") != NULL) ! return LoadJPG (image, type); ! #endif ! return false; } *************** *** 367,376 **** return true; } bool Texture::LoadJPG (char* image, texType type) { ! return false; } bool Texture::LoadArray (unsigned char* data, int w, int h, texType t) { --- 377,483 ---- return true; } + #ifdef TGSDL_IMAGE + //Code emprunte a Ogre3D + void Texture::FlipAroundY (int w, int h, unsigned char* pixels) + { + //on considere qu'on est en RGB8 + unsigned char* buffer = new unsigned char [w*h*3]; + unsigned char* dst = NULL; + unsigned char* src = pixels; + for (int y=0; y<h; y++) + { + int offset = ((y * w) + (w - 1)) * 3; + dst = buffer; + dst += offset; + for (int x=0; x<w; x++) + { + memcpy (dst, src, sizeof(unsigned char)*3); + dst -= 3; + src += 3; + } + } + memcpy (pixels, buffer, w*h*sizeof(unsigned char)*3); + delete buffer; + } + + void Texture::FlipAroundX (int w, int h, unsigned char* pixels) + { + //on considère qu'on est en RGB8 + int rowSpan = w*3; + unsigned char* buffer = new unsigned char [rowSpan*h]; + unsigned char* ptr1 = pixels, *ptr2 = buffer + ((h-1)*rowSpan); + for (int i=0; i<h; i++) + { + memcpy (ptr2, ptr1, rowSpan); + ptr1 += rowSpan; + ptr2 -= rowSpan; + } + memcpy (pixels, buffer, rowSpan*h); + delete buffer; + } + + + bool Texture::LoadPNG (char* image, texType type) + { + std::cout << "chargement de "<<image<<std::endl; + SDL_Surface* texture; + texture = IMG_Load(image); + + if (texture == NULL) + return false; + FlipAroundX (texture->w, texture->h, (unsigned char*)texture->pixels); + // FlipAroundX (texture->w, texture->h, (unsigned char*)texture->pixels); + // texture->pixels = ChangeTextureOrientation(texture->w, texture->h, (unsigned char*)texture->pixels); + + glGenTextures (1, &iId); + glBindTexture(GL_TEXTURE_2D, iId); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); + //TODO: CLAMP TO EDGE FAIT BUGGUER LES MAPS + //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_WRAP_R, GL_CLAMP_TO_EDGE); + //priorite de la texture... ca ne semble pas vraiment utile + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, 1); + + gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, texture->w, texture->h, GL_RGB, GL_UNSIGNED_BYTE, texture->pixels); + SDL_FreeSurface(texture); + + return true; + } bool Texture::LoadJPG (char* image, texType type) { ! std::cout << "chargement de "<<image<<std::endl; ! ! SDL_Surface* texture; ! texture = IMG_Load(image); ! ! if (texture == NULL) ! return false; ! ! FlipAroundX (texture->w, texture->h, (unsigned char*)texture->pixels); ! ! glGenTextures (1, &iId); ! glBindTexture(GL_TEXTURE_2D, iId); ! ! glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST); ! glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); ! //TODO: CLAMP TO EDGE FAIT BUGGUER LES MAPS ! //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_WRAP_R, GL_CLAMP_TO_EDGE); ! //priorite de la texture... ca ne semble pas vraiment utile ! //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, 1); ! ! gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, texture->w, texture->h, GL_RGB, GL_UNSIGNED_BYTE, texture->pixels); ! SDL_FreeSurface(texture); ! ! return true; } + #endif + bool Texture::LoadArray (unsigned char* data, int w, int h, texType t) { Index: texture.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/texture.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** texture.h 26 Sep 2004 13:15:17 -0000 1.1.1.1 --- texture.h 27 Sep 2004 21:34:05 -0000 1.2 *************** *** 88,93 **** --- 88,98 ---- bool LoadBMP (char*, texType); bool LoadTGA (char*, texType); + #ifdef TGSDL_IMAGE bool LoadJPG (char*, texType); + bool LoadPNG (char*, texType); + #endif bool LoadWhite (); + void FlipAroundY (int, int, unsigned char*); + void FlipAroundX (int, int, unsigned char*); texType GetTexType () { return tType; } unsigned int iId; Index: glrenderernv15.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/glrenderernv15.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** glrenderernv15.cc 27 Sep 2004 13:32:34 -0000 1.3 --- glrenderernv15.cc 27 Sep 2004 21:34:05 -0000 1.4 *************** *** 373,377 **** pDefaultFont = new Font(); ! LoadFont(pDefaultFont, "data/font.bmp"); bWireFrame = false; --- 373,377 ---- pDefaultFont = new Font(); ! LoadFont(pDefaultFont, "data/font.jpg"); bWireFrame = false; |