M
Michael Sgier
Hello
i don't understand the visibility/passing of variables. I've in
texture.h:
class CTexture
{
public:
unsigned int texID;
GLuint texture[5];
int LoadTex(char* filename);
}
and in terrain.h:
class CTerrain
{
public:
CTexture ebene;
}
the texture loading function in texture.cpp:
int CTexture::LoadTex(char* filename)
{
static int i = 0;
SDL_Surface* img;
img = SDL_LoadBMP(filename);
if (!img) {
printf("Error: %s\n", SDL_GetError());
exit(1);
}
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, FILTER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, FILTER);
glTexImage2D(GL_TEXTURE_2D, 0, 3, img->w, img->h, 0, GL_RGB,
GL_UNSIGNED_BYTE, img->pixels);
printf("loaded file '%s' as texture %i\n", filename, i);
i++;
return 0;
}
and finally the function gets called in terrain.cpp
#include "terrain.h"
ebene.LoadTex("pics/ground.bmp");
also another function here uses the variable:
void CTerrain::OnDraw()
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, ebene.texID);
....
}
It compiles but the texture doesn't get drawed. I dont understand how to
pass texture[] and how to
draw it then. Also where texture[] is visible.
THANKS and regards
Michael
i don't understand the visibility/passing of variables. I've in
texture.h:
class CTexture
{
public:
unsigned int texID;
GLuint texture[5];
int LoadTex(char* filename);
}
and in terrain.h:
class CTerrain
{
public:
CTexture ebene;
}
the texture loading function in texture.cpp:
int CTexture::LoadTex(char* filename)
{
static int i = 0;
SDL_Surface* img;
img = SDL_LoadBMP(filename);
if (!img) {
printf("Error: %s\n", SDL_GetError());
exit(1);
}
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, FILTER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, FILTER);
glTexImage2D(GL_TEXTURE_2D, 0, 3, img->w, img->h, 0, GL_RGB,
GL_UNSIGNED_BYTE, img->pixels);
printf("loaded file '%s' as texture %i\n", filename, i);
i++;
return 0;
}
and finally the function gets called in terrain.cpp
#include "terrain.h"
ebene.LoadTex("pics/ground.bmp");
also another function here uses the variable:
void CTerrain::OnDraw()
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, ebene.texID);
....
}
It compiles but the texture doesn't get drawed. I dont understand how to
pass texture[] and how to
draw it then. Also where texture[] is visible.
THANKS and regards
Michael