Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Kheteris

World in a text file

This topic is 5344 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I''m just playing with lesson 10, and I''m trying to combine it with lesson 23, where I can load multiple textures and I was wondernig if I could do commands, like the glBindTexture() command inside the Text file... I want to be able to load the walls to have different textures then the floors etc. etc. Shouldn''t be that hard, but I can''t just implement the code right inbetween the text doc...

Share this post


Link to post
Share on other sites
Advertisement
instead of doing commands in the text file, why don't you just load a list of textures? check how many there are on the list and you use a for loop to put the loaded textures into an array that fits every single texture !

[edited by - JazzD on January 22, 2004 3:29:02 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
This is my World.txt, with a number (0,1,2) defining texture:
NUMPOLLIES 36

// Floor 1
1
-3.0 0.0 -3.0 0.0 6.0
-3.0 0.0 3.0 0.0 0.0
3.0 0.0 3.0 6.0 0.0
1
-3.0 0.0 -3.0 0.0 6.0
3.0 0.0 -3.0 6.0 6.0
3.0 0.0 3.0 6.0 0.0

// Ceiling 1
2
-3.0 1.0 -3.0 0.0 6.0
-3.0 1.0 3.0 0.0 0.0
3.0 1.0 3.0 6.0 0.0
2
-3.0 1.0 -3.0 0.0 6.0
3.0 1.0 -3.0 6.0 6.0
3.0 1.0 3.0 6.0 0.0

// A1
0
-2.0 1.0 -2.0 0.0 1.0
-2.0 0.0 -2.0 0.0 0.0
-0.5 0.0 -2.0 1.5 0.0
0
-2.0 1.0 -2.0 0.0 1.0
-0.5 1.0 -2.0 1.5 1.0
-0.5 0.0 -2.0 1.5 0.0

// A2
0
2.0 1.0 -2.0 2.0 1.0
2.0 0.0 -2.0 2.0 0.0
0.5 0.0 -2.0 0.5 0.0
0
2.0 1.0 -2.0 2.0 1.0
0.5 1.0 -2.0 0.5 1.0
0.5 0.0 -2.0 0.5 0.0

// B1
A N D SO ON

typedef struct tagTRIANGLE
{
VERTEX vertex[3];
int tex; //added tex identifier
} TRIANGLE;


void SetupWorld()
{
float x, y, z, u, v;
int numtriangles;
FILE *filein;
char oneline[255];
filein = fopen("data/world.txt", "rt"; // File To Load World Data From

readstr(filein,oneline);
sscanf(oneline, "NUMPOLLIES %d\n", &numtriangles);

sector1.triangle = new TRIANGLE[numtriangles];
sector1.numtriangles = numtriangles;
for (int loop = 0; loop < numtriangles; loop++)
{
readstr(filein,oneline);
sscanf(oneline,"%d", &sector1.triangle[loop].tex); //loading texture attribute

for (int vert = 0; vert < 3; vert++)
{

readstr(filein,oneline);

sscanf(oneline, "%f %f %f %f %f", &x, &y, &z, &u, &v);
sector1.triangle[loop].vertex[vert].x = x;
sector1.triangle[loop].vertex[vert].y = y;
sector1.triangle[loop].vertex[vert].z = z;
sector1.triangle[loop].vertex[vert].u = u;
sector1.triangle[loop].vertex[vert].v = v;
}
}
fclose(filein);
return;
}

Share this post


Link to post
Share on other sites
My basic world text files look like this:
// Vertices? Colors? Normals? Textures?

1 0 0 1
// If there are textures, how many?

3
// Begin reading texture filenames (the : is to specify where it starts

:grond.bmp
muur.bmp
dak.bmp

// How many triangles

14
// Triangles: Texture Number

0
// Vertex Texture Coordinate

-10 -10 0 0 0
10 -10 0 1 0
10 10 0 1 1

// And so on...

0
10 10 0 1 1
-10 10 0 0 1
-10 -10 0 0 0

1
-2 2 0 0 0
2 2 0 1 0
2 2 3 1 1

1
2 2 3 1 1
-2 2 3 0 1
-2 2 0 0 0

1
-2 -2 0 0 0
2 -2 0 1 0
2 -2 3 1 1
// And a lot more triangles

This is pretty handy for simply testing if a modelling/animation program works, easy to implement and easy to make.

Share this post


Link to post
Share on other sites
Hrmmm... maybe I miss worded my question, like what JazzD said, I should put the traingles into an array.

But, I should begin to completly understand the code.

I use the same code as the Anonymous poster (NeHe''s basecode from lesson 10).

From my understanding it does this:

1)Defines Floats which will be used to define the location of the triangles.

2)Opens and reads the text document which holds the list of textures.

3) sscanf(oneline, "NUMPOLLIES %d\n", &numtriangles); <--- counts the number of triangles?

4) sector1.triangle = new TRIANGLE[numtriangles];
sector1.numtriangles = numtriangles; <--- makes the array which holds all of the coords for the triangles.

5)


for (int loop = 0; loop < numtriangles; loop++)
{
for (int vert = 0; vert < 3; vert++)
{
readstr(filein,oneline);
sscanf(oneline, "%f %f %f %f %f", &x, &y, &z, &u, &v);
sector1.triangle[loop].vertex[vert].x = x;
sector1.triangle[loop].vertex[vert].y = y;
sector1.triangle[loop].vertex[vert].z = z;
sector1.triangle[loop].vertex[vert].u = u;
sector1.triangle[loop].vertex[vert].v = v;
}
}

^ This goes through the text document assigning each triangle section to the array:: and displays it?

6) Closes the file

I guess my question is where do I do the glBindTexture() -ing?
Should I cut the loop in half so after it displays X amount of triangles I change the texture?

Need guidance

Share this post


Link to post
Share on other sites
Place the texture number before every triangle in your text file and, when you draw a triangle get the texture number (stored in an array, just like the vertices and texture coordinates) and bind the specified texture with glBindTexture (or you could first check if the specified texture isn''t binded already, this for speed reasons).

Share this post


Link to post
Share on other sites
Ive been playing with lesson 10

I am using multiple textures


int LoadGLTextures() // Load Bitmaps And Convert To Textures

{
int Status=FALSE; // Status Indicator

AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture

glGenTextures(array[0].txtcount, &texture[0]); // Create Textures


for (int loop=1; loop < 99; loop++)
{
switch (array[0].txtused[loop])
{
case 0 :
{
break;
}
case 1 : // 1= used

{
memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL (clears memory)

if (TextureImage[0]=LoadBMP(array[loop].txtfilename))
{
Status=TRUE; // Set The Status To TRUE


// Create Nearest Filtered Texture

// glBindTexture(GL_TEXTURE_2D, texture[loop]);

// glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);

// glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);

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

// Create Linear Filtered Texture

// glBindTexture(GL_TEXTURE_2D, texture[loop]);

// glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

// glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

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


// Create MipMapped Texture

glBindTexture(GL_TEXTURE_2D, texture[loop]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_NEAREST);
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 Texture Exists

{
if (TextureImage[0]->data) // If Texture Image Exists

{
free(TextureImage[0]->data); // Free The Texture Image Memory

}
free(TextureImage[0]); // Free The Image Structure

}
return Status; // Return The Status

}


array is somewhere to store the textures i use

In the DrawGLScene i added

graphics = sector1.triangle[loop_m].vertex[0].gfx; // select texture from world data

glBindTexture(GL_TEXTURE_2D, texture[graphics]); // this must be outside glBegin glEnd



In SetupWorld() i added


for (int vert = 0; vert < 3; vert++) // This loop builds a vector list

{
// readstr(filein,oneline); // read a line

sscanf(oneline, "%f %f %f %f %f", &x, &y, &z, &u, &v); // get vectors and store

sector1.triangle[loop].vertex[vert].x = x;
sector1.triangle[loop].vertex[vert].y = y;
sector1.triangle[loop].vertex[vert].z = z;
sector1.triangle[loop].vertex[vert].u = u;
sector1.triangle[loop].vertex[vert].v = v;
sector1.triangle[loop].vertex[vert].gfx = gfx; // This is the Texture



Not the easiest way but quick and simply when just playing around, i did this within a week of starting with opengl and its only 10 years since i did any C programming. I got that to work now playing with light which is proving to be abit of a pain (normals problem i think)

add these to give you simply movement in the Y axis

GLfloat y=0.0f; // y offset moves up and down


(this ones in the DrawScene()
GLfloat ytrans = y-walkbias-0.25f; // added y to give it up down




if (keys[''A''])
{
y-= 0.04f;
}

if (keys[''Z''])
{
y+= 0.04f;
}



just stick them in the right places
Hope this helps
Just going to climb into my flame proof suit tobe ready..

Share this post


Link to post
Share on other sites
Well, I haven't been able to do any programming lately cuz my school account was disabled :/ but I got it back like 20 minutes ago and started working on my project. I was able to do everything you said unfinished, no errors or nothing, it's just that when I try and run the program, it just stops responding... maybe I told it to do too much?

EDIT: Oh, and while I'm at it, the variable, graphic, is the variable for the number for the texture I want to load from the array, right?

[edited by - Kheteris on January 29, 2004 1:46:41 PM]

Share this post


Link to post
Share on other sites
Bumb

I''m 99% positive that I am not missing anything, no errors, no warnings etc etc, I added the m_gfx variable everwhere I saw m_x, m_y etc etc...

Why would it just stop responding? Am I telling it to do to much?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!