Skip to main content
GameDev.net gamedev.net
🔒 Locked

resizing an array

Started by Fluid FX Jul 31, 2002 at 8:35 AM 8 replies 650+ views
Original Post
Fluid FX
Fluid FX
Ok my first real question... when i started opengl coding, like 5 months ago, i was wondering how to actually resize an array.. in the nehe tutorials you make structures and then use sector1.triangles = new TRIANGLE[numtriangles]; now i thought like, why not make the structure sector so it can load more textures.. struct SECTOR { int numtriangles; int numtextures; TRIANGLE* triangle; GLuint texture[1]; }; and then use sector1.trangle = new TRIANGLE[numtriangles]; sector1.texture = new GLuint[numtextures]; but then it gives me this error: cannot convert from 'struct TRIANGLE *' to 'unsigned int [1]' :S GreetS //edit oh yes i forgot to mention the basecode is from nehe, i devided it into pieces, i use main.h to declare for example the structs in! [edited by - Fluid FX on July 31, 2002 9:36:31 AM]
eloso
eloso
well this has nothing to do with resizing an array, but with dynamically allocating it. In this case you should use

GLuint *texture;

in your struct.
Fluid FX
Fluid FX
ok now i might be annoying, but now it stucks here

glBindTexture(GL_TEXTURE_2D,sector1.texture[0]);

bah :-)

the debug doesn''t say anything
but the program stops and then winxp gives an error

Greets
niyaw
niyaw
std::vector will cure all your problems

you can write:

  
struct SECTOR
{
int numtriangles;
int numtextures;
std::vector<TRIANGLE> triangle;
std::vector<GLuint> texture;
};
// resize triangles and textures

sector.triangle.resize(10);
sector.texture.resiz(5);
// use

glYadda(sector.texture[2]);

you need to resize vectors before you can access their elements.

---
Come to #directxdev IRC channel on AfterNET
Fluid FX
Fluid FX
sorry to dissapoint you but it still stucks on the second problem

glBindTexture(GL_TEXTURE_2D,sector1.texture[0]);

i am sure it''s that.
niyaw
niyaw
- did you resize the texture array?

- did you initialize that texture after resizing the array?

---
Come to #directxdev IRC channel on AfterNET
force_of_will
force_of_will
Maybe it as nothing to do with your inicial problem but with your loading textures code place it in the forum so we can see
Fluid FX
Fluid FX
#include "main.h"


AUX_RGBImageRec *LoadBMP(char *Filename)
{
FILE *File=NULL;

if(!Filename)
{
return NULL;
}

File = fopen(Filename,"r");

if(File)
{
fclose(File);
return auxDIBImageLoad(Filename);
}
return NULL;
}

int LoadGLTextures()
{
int Status=FALSE;

AUX_RGBImageRec *TextureImage[1];

memset(TextureImage,0,sizeof(void *)*1);

if(TextureImage[0]=LoadBMP("Mud.bmp"))
{
Status=TRUE;

}
else


glGenTextures(1,&sector1.texture[0]);

glBindTexture(GL_TEXTURE_2D, sector1.texture[0]);



glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);

gluBuild2DMipmaps(GL_TEXTURE_2D,3,TextureImage[0]->sizeX, TextureImage[0]->sizeY,GL_RGB,GL_UNSIGNED_BYTE,TextureImage[0]->data);

if(TextureImage[0])
{
if(TextureImage[0]->data)
{
free(TextureImage[0]->data);
}
free(TextureImage[0]);
}

return Status;
}

can someone explain me how to make those kewl funny textboxes so you don''t have a reply of 10 miles long?

Greetz
Deyja
Deyja
When you bind a texture, you don''t bind a variable, you just bind an integer. So, stick a ''0'' there instead of ''sector.textures[0]'' and it will work. Or, you can make sure sector.textures[0] equals 0, and use it the way it is.

Right now, it hasn''t been initiliazed, so you are trying to bind something like ''-342192348'', which, it doesn''t like.
weasalmongler
weasalmongler
1) MAKE SURE THAT YOU ALLOCATE MEMORY FOR YOUR POINTER! You have a "GLuint *texture;", make sure you allocate it with

texture = new GLuint[numTextures];

2) Make sure when calling glGenTextures(); you call it like this:

glGenTextures(1, & sector.texture[0]);

Don''t forget the and symbol thing.

3) Make sure that number (1) has been carried out before step (2) or you will have problems.

- Weasalmongler

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.