Floor Problem
Hi there, I'm a little new to OpenGL and I've run into a problem with a project I'm working on, which I was hoping someone might be able to help me with. I'm working on creating a small FPS as a learning project and I'm currently at the stage of implementing the map loading system. I can get all of the faces and such to load correctly, but I've suddenly realised I have no way of determining how to map the textures for the floors. The map system is basically a collection of shapes which are viewed in the editor in 2D and are translated to 3D in the compilation process. The floor is a polygon which can have any number of sides (the number of sides depends on the number of walls in the room) and it is this which makes the mapping coordinates hard to determine. I looked into the glTexGenf function but I've got no idea about how it works. I got to the point where I was displaying a texture but there seemed to be no way to stop it from stretching or shrinking vastly.
Basically I'm hoping if anyone knows a method to automatically determine the mapping of a texture to the floor polygon. Any help (even just a slightly more detailed explanation of the glTexGenfv function) would be much appreciated.
The solution to this problem I think lies in how you store your maps. Usually, maps/levels are stored with verts to the triangles, also texture coords/normals, etc.., kind of like 3d models in that sense, though they may contain BSP tree data as well. The method you use works to draw, but I don't see any way to get TexCoords. I'd start there.
Automatic mapping is a pain in the you know what, the best way is to do it manualy or by projecting the texture coordinates in some way.
For you, the simplest way would be to just take the initial 2D coordinates and scale(and possibly translate/rotate as needed) them acording to your liking, that way you get a nice tiling surface that joins up nicly with neighbouring polygons.
For you, the simplest way would be to just take the initial 2D coordinates and scale(and possibly translate/rotate as needed) them acording to your liking, that way you get a nice tiling surface that joins up nicly with neighbouring polygons.
www.flashbang.se | www.thegeekstate.com | nehe.gamedev.net | glAux fix for lesson 6 | [twitter]thegeekstate[/twitter]
Thanks for your suggestions. lc_overlord, are you saying that when I run the maps through my compiler I should determine the coordinates based on the 2D representation of them in the editor? I considered creating a kind of imaginary rectangle representing the bounds of the floor polygon and then using that to align the texture, but I'm unsure how I would determine what the mapping coordinates were at any one vertex. Is it possible to do it in such a way that I need only specify four mapping coordinates no matter how many corners? Sorry if this is a silly question but like I said I'm new to OpenGL and I seem to have been unable to find any documentation directly relating to this question.
Thank you for your promt replies to the question :).
Thank you for your promt replies to the question :).
As a starting point you could simply set the texture coordinate to the vertices 2d location and set the texture to wrap. Then see if you can get what you wanted from there by scaling, paning, using a more complex projection scheme, whatever seems appropriate. You could use texture coordinate generation to do this for you, but in my experience it's no faster and is more confusing.
To base your texture coordinates off a rectangle, do this:
Pretty simple huh?
To base your texture coordinates off a rectangle, do this:
float MinX, MinY, MaxX, MaxY; //set these to your rectanglefloat x, y; //and this is your vertices 2d locationfloat CoordX = (x - MinX) / (MaxX - MinX);float CoordY = (y - MinY) / (MaxY - MinY);
Pretty simple huh?
___________________________________________________David OlsenIf I've helped you, please vote for PigeonGrape!
RAZORUNREAL, you hit the nail on the head with that suggestion. Thank you very much for that, it's exactly what I needed! Problem solved. lc_overlord and kburkhart84, thank you too for your contributions and thank you all for your quick responses. I may yet finish this project :)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement