Advertisement

Problems with making a light reader

Started by October 22, 2004 05:20 AM
16 comments, last by Enigma 20 years ago
Thanks, though i have already removed the glBindTexture in drawlglscene.
I'll try your code aswell.
Though:
#include <cmath>#include <deque>#include <fstream>#include <map>


I've never worked with those headers before...
Any tuts on them somewhere available?
cmath is just the C header math.h properly encapsulated in the std namespace. deque is a double-ended queue. It is similar to a vector but expanding a deque is often faster than growing a vector, although storage is not necessarily contiguous. fstream is the header that contains C++'s classes for typesafe file input/output. map is an associative container that maps unique keys to values, much like an associative array in other languages. A quick google search should give you plenty of tutorials on these, for example deque, fstream and map.

Enigma
Advertisement
Ok i've tried your code (been busy with other things, Max Payne modding mostly), had to rename all the nullptrs to NULL, and it crashed. No error or something, no 'Report to Microsoft' message, just a crash back to Desktop.
Is this something that has to do with how the world.txt looks?
If it is, please tell me how it loads the textures from world.txt.
Cheers.
Probably it can't find the texture and is throwing an exception. Since the exception is not caught the program terminates with an abnormal program termination error.

Try changing this code:
		/* Does this line contain texture information? */		else if (reader.peek() == 't')		{			readTexture(reader);		}

to this:
		/* Does this line contain texture information? */		else if (reader.peek() == 't')		{			try			{				readTexture(reader);			}			catch (std::string& exception)			{				MessageBox(nullptr, exception.c_str(), "Texture Error", MB_OK | MB_ICONINFORMATION);				return false;			}		}


Enigma
Allright, please tell me what the texture loading line in world.txt should be. And btw, the textures in the normal NeHe lesson 10 stopped showing up aswell... Does anyone know the reason for it to happen? (The meshes are not white like a usual not-textured and not coloured object, they're black...)
Cheers.
I used your format, so the world data file should contain lines like:
t filename.bmp identifier

Note that if your textures are in the 'data' directory you need that to be:
t data/filename.bmp identifier

I tested the code before I posted it and it worked fine.

Enigma
Advertisement
Alright, it works now, but if i use more of that line, it just uses the first one.
I tried to solve this, but i couldn't..
Could you please tell me how to modifiy it?
Cheers.
What did you try?

The easiest way to change this would be to modify the definition of each triangle to include a texture. That means you're going to need to modify:
struct Triangle{	Vertex vertex[3];};

to allow you to reference the texture needed for the triangle,
/* Read a triangle from a file stream */void readTriangle(std::ifstream& reader){	Triangle triangle;	readVertex(reader, triangle.vertex[0]);	readVertex(reader, triangle.vertex[1]);	readVertex(reader, triangle.vertex[2]);	/* We use a deque, so push the triangle onto the back of it */	sector1.triangle.push_back(triangle);}

to add the id of the texture to the triangle and
int DrawGLScene(GLvoid)									// Here's Where We Do All The Drawing{	// code	glBindTexture(GL_TEXTURE_2D, textures["1"]);		// Process Each Triangle	for (int loop_m = 0; loop_m < sector1.triangle.size(); loop_m++)	{		// code	}	return TRUE;										// Everything Went OK}

to bind the correct texture for each triangle.

Enigma

This topic is closed to new replies.

Advertisement