psykocrash
Messages postés240Date d'inscriptionvendredi 14 juin 2002StatutMembreDernière intervention17 mars 2009
-
8 janv. 2006 à 17:22
psykocrash
Messages postés240Date d'inscriptionvendredi 14 juin 2002StatutMembreDernière intervention17 mars 2009
-
15 janv. 2006 à 21:58
Bonjour,
J'ai commencé depuis peut la programmation avec OpenGL/GLut et j'ai
trouvé la classe TGA Loader de Funto66 mais je n'arrive pas à afficher
les textures.
Voila le code source de mon application, j'espère que vous trouverez d'où vient l'erreur...
<hr size="2" width="100%">/*
* Apprendre l'OpenGL / Glut
* par Psykocrash
*
* Lexique :
* - Vertex : ? (Liste de sommets ou Point)
*/
// -Inclusion des fichiers en-tête-
#ifdef WIN32
#include <windows.h>
#endif
#include <stdio.h>
#include <gl/gl.h>
#include <gl/glut.h>
// Classe codée par Funto (funto66@gmail.com)
#include <TGALoader/TGALoader.cpp>
// -Constantes-
#define TEXTURE_HERO 1
// -Déclaration des prototypes-
void Display(void);
void Reshape(int, int);
void ChargerTexture(char *Chemin, int id);
void DessinerTexture(int Id, int X, int Y, int Largeur, int Hauteur,
int X_src, int Y_src, int Largeur_src, int Hauteur_src, float
Transparence);
// -Fonctions-
int main(int argc, char *argv[])
{
// Initialisation
glutInit(&argc, argv); // Initialisation de GLUT
glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE); // Couleurs vraies, un seul tampon
// Paramètres de la fenêtre
glutInitWindowSize(640, 480); // Taille 640*480
//-> Pour un affichage en plein écran, remplacer glutInitWindowSize() par glutFullScreen()
glutInitWindowPosition(50, 50); // Position
glutCreateWindow("Fenetre OpenGL"); // Création de la fenêtre
// Chargement des textures
ChargerTexture("C:\\hero.tga", TEXTURE_HERO);
// Callbacks
glutDisplayFunc(Display); // Affichage
//glutReshapeFunc(Reshape); // Création et redimension de la fenêtre
textureTGA::textureTGA(const char *filename, const int textureId){
byte *imageData;
int numPixels;
int bytesInPixel;
int imageDataSize;
headerTga fileHeader;
byte temp;
// Open file
std::ifstream textureFile(filename, std::ios::in | std::ios::binary | std::ios::ate);
if(!textureFile.is_open()){
std::cout<<"[TGA] ERROR: Could not open '"<<filename<<"'"<<std::endl;
return;
}
if(int(textureFile.tellg()) == 0){
std::cout<<"[TGA] ERROR: Texture '"<<filename<<"' is empty"<<std::endl;
textureFile.close();
return;
}
// We only support uncompressed 24 or 32 bits per pixel TGAs
if(fileHeader.colorMapType == 1 || int(fileHeader.imageType) != 2){
std::cout<<"[TGA] ERROR: '"<<filename<<"' is an texture invalid format\n[TGA] ERROR: It should be an uncompressed 24/32bpp TGA"<<std::endl;
textureFile.close();
return;
}
if(m_bpp != 32 && m_bpp != 24){
std::cout<<"[TGA] ERROR: Invalid texture color depth, '"<<filename<<"' must be uncompressed 24/32bpp TGA"<<std::endl;
textureFile.close();
return;
}
// OpenGL textures must be power-of-two
/*if((m_width&(m_width-1)) || (m_height&(m_height-1))){
std::cout<<"[TGA] ERROR: Texture '"<<filename<<"' must have power-of-two width & height"<<std::endl;
textureFile.close();
return;
}*/
// Determine format
switch(m_bpp){ case 24:m_format GL_RGB; bytesInPixel 3; break; case 32:m_format GL_RGBA; bytesInPixel 4; break;
default:
std::cout<<"[TGA] ERROR: Invalid texture color depth, '"<<filename<<"' must be uncompressed 24/32bpp TGA"<<std::endl;
textureFile.close();
return;
break;
}
// Allocate memory for image
numPixels = m_width * m_height;
imageDataSize = numPixels * bytesInPixel;
imageData = new byte[imageDataSize];
if(!imageData){
std::cout<<"[TGA] ERROR: Out of memory"<<std::endl;
textureFile.close();
return;
}
// Read image data
textureFile.seekg(18, std::ios::beg);
textureFile.read((char*)imageData, imageDataSize);
textureFile.close();
Alucards
Messages postés40Date d'inscriptionmercredi 26 mars 2003StatutMembreDernière intervention 3 septembre 2008 15 janv. 2006 à 20:32
j'ai codé un loader dynamique tga/bmp/pcx/jpg je l'ameliore au fur et a
mesure mais pour le tga je me suis inspirer du loader de funtoo donc si
ca t'intersee regarde a ce lien
Tous les chemins mènent au RHUM !!!!!!!!!!!!!!!!!!!..............................