M
Michael Sgier
Hello
in terrain.cpp i want to load a texture:
// load texture
terrainTex[0].LoadTex("pics/ground.bmp", *terrainTex[]);
in texture.cpp:
/* Texturen laden & generieren */
int CTexture::LoadTex(char* filename, CTexture* terrainTex[])
{
/* mit dieser Variablen z�len wir die Textur-ID's hoch */
static int i = 0;
SDL_Surface* img;
img = SDL_LoadBMP(filename);
if (!img) {
printf("Error: %s\n", SDL_GetError());
exit(1);
}
//glGenTextures(1, &terrainTex[0].texID);
glGenTextures(1, &terrainTex);
glBindTexture(GL_TEXTURE_2D, terrainTex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //or GL_CLAMP
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //or GL_CLAMP
// glTexImage2D(GL_TEXTURE_2D, 0, 3, img->w, img->h, 0, GL_RGB,
GL_UNSIGNED_BYTE, img->pixels);
// glTexImage2D(GL_TEXTURE_2D, 3, img->w, img->h, GL_RGB,
GL_UNSIGNED_BYTE, img->pixels);
// gluBuild2DMipmaps(GL_TEXTURE_2D, 0, 3, img->w, img->h, 0, GL_RGB,
GL_UNSIGNED_BYTE, img->pixels);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, img->w, img->h, GL_RGB,
GL_UNSIGNED_BYTE, img->pixels);
//
//gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, terrainTex[0].width,
terrainTex[0].height, GL_RGB, GL_UNSIGNED_BYTE, terrainTex[0].data);
printf("loaded file '%s' as texture %i\n", filename, i);
i++;
return 0;
}
in texture.h:
class CTexture
{
public:
int LoadTex(char* filename, CTexture* terrainTex[]);
in terrain.h:
class CTerrain
{
public:
CTexture terrainTex[5]; // for multiple textures on the terrain
}
this is confusing me. I'm unshure when to put terrainTex[5],
terrainTex[] or terrainTex :-/ Maybe someone
is more shure on this?
THANKS and regards
Michael
in terrain.cpp i want to load a texture:
// load texture
terrainTex[0].LoadTex("pics/ground.bmp", *terrainTex[]);
in texture.cpp:
/* Texturen laden & generieren */
int CTexture::LoadTex(char* filename, CTexture* terrainTex[])
{
/* mit dieser Variablen z�len wir die Textur-ID's hoch */
static int i = 0;
SDL_Surface* img;
img = SDL_LoadBMP(filename);
if (!img) {
printf("Error: %s\n", SDL_GetError());
exit(1);
}
//glGenTextures(1, &terrainTex[0].texID);
glGenTextures(1, &terrainTex);
glBindTexture(GL_TEXTURE_2D, terrainTex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //or GL_CLAMP
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //or GL_CLAMP
// glTexImage2D(GL_TEXTURE_2D, 0, 3, img->w, img->h, 0, GL_RGB,
GL_UNSIGNED_BYTE, img->pixels);
// glTexImage2D(GL_TEXTURE_2D, 3, img->w, img->h, GL_RGB,
GL_UNSIGNED_BYTE, img->pixels);
// gluBuild2DMipmaps(GL_TEXTURE_2D, 0, 3, img->w, img->h, 0, GL_RGB,
GL_UNSIGNED_BYTE, img->pixels);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, img->w, img->h, GL_RGB,
GL_UNSIGNED_BYTE, img->pixels);
//
//gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, terrainTex[0].width,
terrainTex[0].height, GL_RGB, GL_UNSIGNED_BYTE, terrainTex[0].data);
printf("loaded file '%s' as texture %i\n", filename, i);
i++;
return 0;
}
in texture.h:
class CTexture
{
public:
int LoadTex(char* filename, CTexture* terrainTex[]);
in terrain.h:
class CTerrain
{
public:
CTexture terrainTex[5]; // for multiple textures on the terrain
}
this is confusing me. I'm unshure when to put terrainTex[5],
terrainTex[] or terrainTex :-/ Maybe someone
is more shure on this?
THANKS and regards
Michael