array

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
 
M

msalters

Michael Sgier schreef:
Hello ....
I'm unshure when to put terrainTex[5], terrainTex[] or terrainTex
Maybe someone is more shure on this?

Raw arrays aren't for beginners. Try std::vector<terrainTex>. It's
like an array that you can use to get the i'th element. However,
it starts at size 0, at any moment you can ask for its current size(),
and if you use push_back() or resize() or insert() it will
automatically adjust size().

The only gotcha is that vector<> will move its elements if you add more
than it reserved space for. This happens only if size() would exceed
capacity(). You can use reserve() to set a minimum capacity() to
prevent
this. However, if you're sure you can add all terrainTex objects before
you use them, you don't have to worry about this.

HTH,
Michiel Salters
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top