0 Members and 3 Guests are viewing this topic.
#include <iostream>#include <vector>#include <string>// Typedefstypedef char CHAR ;typedef unsigned __int8 UBYTE ;typedef UBYTE ubyte ;typedef unsigned __int16 WORD ;typedef WORD word ;typedef unsigned __int16 USHORT ;typedef USHORT ushort ;typedef short SHORT ;typedef unsigned __int32 DWORD ;typedef DWORD dword ;typedef long LONG ;typedef unsigned __int32 ULONG ;typedef ULONG ulong ;typedef signed __int64 QUAD ;typedef QUAD quad ;typedef unsigned __int64 UQUAD ;typedef UQUAD uquad ;typedef float FLOAT ;typedef double DOUBLE ;//primstemplate<class T>T read_bin(std::istream& is){ T tmp; is.read( reinterpret_cast<char*>( &tmp ), sizeof( T ) ); return tmp;}std::string read_string( std::istream& is, int full_length ){ int length = read_bin<CHAR>( is ); std::vector<CHAR> tmp( full_length ); is.read( &tmp[0], tmp.size() ); return std::string( tmp.begin(), tmp.begin() + length );}// Basic aux structurestypedef enum TF { F = 0, T} BOOL_PMS;typedef enum POLYTYPE { ptNORMAL = 0, ptONLY_BULLETS_COLLIDE, ptONLY_PLAYERS_COLLIDE, ptNO_COLLIDE, ptICE, ptDEADLY, ptBLOODY_DEADLY, ptHURTS, ptREGENERATES, ptLAVA} PMS_POLYTYPE;typedef enum DRAWBEHIND { dbBEHIND_ALL = 0, dbBEHIND_MAP, dbBEHIND_NONE} PMS_DRAWBEHIND;typedef enum SPECIALACTIONS { saNONE = 0, saSTOP_AND_CAMP, saWAIT_1_SECOND, saWAIT_5_SECONDS, saWAIT_10_SECONDS, saWAIT_15_SECONDS, saWAIT_20_SECONDS} PMS_SPECIALACTIONS;typedef enum WEATHERTYPE { wtNONE = 0, wtRAIN, wtSANDSTORM, wtSNOW} PMS_WEATHERTYPE;typedef enum STEPSTYPE { stHARD_GROUND = 0, stSOFT_GROUND, stNONE} PMS_STEPSTYPE;typedef enum SPAWNTEAM { stGENERAL = 0, stALPHA, stBRAVO, stCHARLIE, stDELTA, stALPHA_FLAG, stBRAVO_FLAG, stGRENADES, stMEDKITS, stCLUSTERS, stVEST, stFLAMER, stBERSERKER, stPREDATOR, stYELLOW_FLAG, stRAMBO_BOW, stSTAT_GUN} PMS_SPAWNTEAM;typedef struct tagPMS_VECTOR { FLOAT x; FLOAT y; FLOAT z;} PMS_VECTOR;typedef struct tagPMS_COLOR { UBYTE blue; UBYTE green; UBYTE red; UBYTE alpha;} PMS_COLOR;// more stufftypedef struct tagPMS_VERTEX { FLOAT x; FLOAT y; FLOAT z; FLOAT rhw; PMS_COLOR color; FLOAT tu; FLOAT tv;} PMS_VERTEX;typedef struct tagPMS_POLYGON { PMS_VERTEX vertex[3]; PMS_VECTOR perpendicular[3]; PMS_POLYTYPE polyType;} PMS_POLYGON;typedef struct tagPMS_SECTOR { WORD polyCount; std::vector<WORD> polys;} PMS_SECTOR;typedef struct tagPMS_PROP { BOOL_PMS active; UBYTE filler1; WORD style; LONG width; LONG height; FLOAT x; FLOAT y; FLOAT rotation; FLOAT scaleX; FLOAT scaleY; UBYTE alpha; UBYTE filler2[3]; PMS_COLOR color; PMS_DRAWBEHIND level; UBYTE filler3[3];} PMS_PROP;typedef struct tagDOSTIME { WORD second : 5; WORD minute : 6; WORD hour : 5; } DOSTIME;typedef struct tagDOSDATE { WORD day : 5; WORD month : 4; WORD year : 7; } DOSDATE;typedef struct tagPMS_TIMESTAMP { DOSTIME time; DOSDATE date;} PMS_TIMESTAMP;typedef struct tagPMS_SCENERY { UBYTE nameLen; std::string name; PMS_TIMESTAMP timestamp;} PMS_SCENERY;typedef struct tagPMS_COLLIDER { BOOL_PMS active; UBYTE filler[3]; FLOAT x; FLOAT y; FLOAT radius;} PMS_COLLIDER;typedef struct tagPMS_SPAWNPOINT { BOOL_PMS active; UBYTE filler[3]; LONG x; LONG y; PMS_SPAWNTEAM team;} PMS_SPAWNPOINT;typedef struct tagPMS_WAYPOINT { BOOL_PMS active; UBYTE filler1[3]; LONG id; LONG x; LONG y; BOOL_PMS left; BOOL_PMS right; BOOL_PMS up; BOOL_PMS down; BOOL_PMS jet; UBYTE path; PMS_SPECIALACTIONS specialAction; UBYTE c2; UBYTE c3; UBYTE filler2[3]; LONG numConnections; LONG connections[20];} PMS_WAYPOINT;// Pms structurestruct pms{ LONG version; std::string name; std::string texture; // these aren't in the map data, but rather calculated on the fly FLOAT leftoffs; FLOAT rightoffs; FLOAT topoffs; FLOAT bottomoffs; // end PMS_COLOR bgColorTop; PMS_COLOR bgColorBottom; LONG jetAmount; UBYTE grenades; UBYTE medikits; PMS_WEATHERTYPE weather; PMS_STEPSTYPE steps; LONG randID; LONG polygonCount; std::vector<PMS_POLYGON> polygon; LONG sectorDivisions; LONG numSectors; std::vector<PMS_SECTOR> sector; LONG propCount; std::vector<PMS_PROP> prop; LONG sceneryCount; std::vector<PMS_SCENERY> scenery; LONG colliderCount; std::vector<PMS_COLLIDER> collider; LONG spawnpointCount; std::vector<PMS_SPAWNPOINT> spawnpoint; LONG waypointCount; std::vector<PMS_WAYPOINT> waypoint;};// Readerstd::istream& operator>>( std::istream& is, pms& p ){ p.version = read_bin<int>( is ); p.name = read_string( is, 38 ); p.texture = read_string( is, 24 ); p.bgColorTop = read_bin<PMS_COLOR>( is ); p.bgColorBottom = read_bin<PMS_COLOR>( is ); p.jetAmount = read_bin<LONG>( is ); p.grenades = read_bin<UBYTE>( is ); p.medikits = read_bin<UBYTE>( is ); p.weather = PMS_WEATHERTYPE(read_bin<UBYTE>( is )); p.steps = PMS_STEPSTYPE(read_bin<UBYTE>( is )); p.randID = read_bin<LONG>( is ); p.polygonCount = read_bin<LONG>( is ); for(int i = 0;i<p.polygonCount;i++) { PMS_POLYGON temp; // cheap solution temp.vertex[0] = read_bin<PMS_VERTEX>( is ); temp.vertex[1] = read_bin<PMS_VERTEX>( is ); temp.vertex[2] = read_bin<PMS_VERTEX>( is ); // calculate stuff for(int m = 0;m < 3;m++){ if(temp.vertex[m].x > p.rightoffs) p.rightoffs = temp.vertex[m].x; if(temp.vertex[m].x < p.leftoffs) p.leftoffs = temp.vertex[m].x; // remember teh y axis is inverted if(temp.vertex[m].y > p.bottomoffs) p.bottomoffs = temp.vertex[m].y; if(temp.vertex[m].y < p.topoffs) p.topoffs = temp.vertex[m].y; } temp.perpendicular[0] = read_bin<PMS_VECTOR>( is ); temp.perpendicular[1] = read_bin<PMS_VECTOR>( is ); temp.perpendicular[2] = read_bin<PMS_VECTOR>( is ); temp.polyType = PMS_POLYTYPE(read_bin<UBYTE>( is )); p.polygon.push_back(temp); } p.sectorDivisions = read_bin<LONG>( is ); p.numSectors = read_bin<LONG>( is ); for(int i = 0;i< ((p.numSectors*2)+1)*((p.numSectors*2)+1);i++){ PMS_SECTOR temp; temp.polyCount = read_bin<WORD>( is ); for(int m = 0;m<temp.polyCount;m++){ temp.polys.push_back(read_bin<WORD>( is )); } p.sector.push_back(temp); } p.propCount = read_bin<LONG>( is ); for(int i = 0;i < p.propCount;i++){ PMS_PROP temp; temp.active = BOOL_PMS(read_bin<UBYTE>( is )); temp.filler1 = read_bin<UBYTE>( is ); temp.style = read_bin<WORD>( is ); temp.width = read_bin<LONG>( is ); temp.height = read_bin<LONG>( is ); temp.x = read_bin<FLOAT>( is ); temp.y = read_bin<FLOAT>( is ); temp.rotation = read_bin<FLOAT>( is ); temp.scaleX = read_bin<FLOAT>( is ); temp.scaleY = read_bin<FLOAT>( is ); temp.alpha = read_bin<UBYTE>( is ); temp.filler2[0] = read_bin<UBYTE>( is ); temp.filler2[1] = read_bin<UBYTE>( is ); temp.filler2[2] = read_bin<UBYTE>( is ); temp.color = read_bin<PMS_COLOR>( is ); temp.level = PMS_DRAWBEHIND(read_bin<UBYTE>( is )); temp.filler3[0] = read_bin<UBYTE>( is ); temp.filler3[1] = read_bin<UBYTE>( is ); temp.filler3[2] = read_bin<UBYTE>( is ); p.prop.push_back(temp); } p.sceneryCount = read_bin<LONG>( is ); for(int i = 0;i < p.sceneryCount;i++){ PMS_SCENERY temp; temp.name = read_string(is, 50); temp.timestamp = read_bin<PMS_TIMESTAMP>( is ); p.scenery.push_back(temp); } p.colliderCount = read_bin<LONG>( is ); for(int i = 0;i < p.colliderCount;i++){ PMS_COLLIDER temp; temp.active = BOOL_PMS(read_bin<UBYTE>( is )); temp.filler[0] = read_bin<UBYTE>( is ); temp.filler[1] = read_bin<UBYTE>( is ); temp.filler[2] = read_bin<UBYTE>( is ); temp.x = read_bin<FLOAT>( is ); temp.y = read_bin<FLOAT>( is ); temp.radius = read_bin<FLOAT>( is ); p.collider.push_back(temp); } p.spawnpointCount = read_bin<LONG>( is ); for(int i = 0;i < p.spawnpointCount;i++){ PMS_SPAWNPOINT temp; temp.active = BOOL_PMS(read_bin<UBYTE>( is )); temp.filler[0] = read_bin<UBYTE>( is ); temp.filler[1] = read_bin<UBYTE>( is ); temp.filler[2] = read_bin<UBYTE>( is ); temp.x = read_bin<LONG>( is ); temp.y = read_bin<LONG>( is ); temp.team = PMS_SPAWNTEAM(read_bin<ULONG>( is )); p.spawnpoint.push_back(temp); } p.waypointCount = read_bin<LONG>( is ); for(int i = 0;i < p.waypointCount;i++){ PMS_WAYPOINT temp; temp.active = BOOL_PMS(read_bin<UBYTE>( is )); temp.filler1[0] = read_bin<UBYTE>( is ); temp.filler1[1] = read_bin<UBYTE>( is ); temp.filler1[2] = read_bin<UBYTE>( is ); temp.id = read_bin<LONG>( is ); temp.x = read_bin<LONG>( is ); temp.y = read_bin<LONG>( is ); temp.left = BOOL_PMS(read_bin<UBYTE>( is )); temp.right = BOOL_PMS(read_bin<UBYTE>( is )); temp.up = BOOL_PMS(read_bin<UBYTE>( is )); temp.down = BOOL_PMS(read_bin<UBYTE>( is )); temp.jet = BOOL_PMS(read_bin<UBYTE>( is )); temp.path = read_bin<UBYTE>( is ); temp.specialAction = PMS_SPECIALACTIONS(read_bin<UBYTE>( is )); temp.c2 = read_bin<UBYTE>( is ); temp.c3 = read_bin<UBYTE>( is ); temp.filler2[0] = read_bin<UBYTE>( is ); temp.filler2[1] = read_bin<UBYTE>( is ); temp.filler2[2] = read_bin<UBYTE>( is ); temp.numConnections = read_bin<LONG>( is ); for(int c=0;c<20;c++){ temp.connections[c] = read_bin<LONG>( is ); } p.waypoint.push_back(temp); } return is;}
#include <gl\gl.h>#include <gl\glut.h>#include <math.h>// this is the header posted above#include "mapc.h"using namespace std;// prototypes for callback funcsvoid init(void);void display(void);void keyboard(unsigned char, int, int);// othervoid glColor4fb(float,float,float,float);// global variables is the way with// this gay callbacks...what a shamepms *pmap;float sfactor = 1.0;float my = 0;float mx = 0;int screen_w = 500;int screen_h = 500;int main (int argc, char *argv[]){ if(argc != 2){ return 0; } // init glut/opengl glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); glutInitWindowSize(screen_w, screen_h); glutInitWindowPosition(-1, -1); // texture stuff glEnable(GL_BLEND); // open the map in question ifstream mapf(argv[1],ios::binary); pms map; // read it and stuff pmap = ↦ mapf >> map; mapf.close(); // it's some kind of magic glutCreateWindow(pmap->name.c_str()); init(); glutDisplayFunc(display); glutIdleFunc(display); glutKeyboardFunc(keyboard); glutMainLoop(); return 0;}void init(void){ glClearColor(0.0, 0.0, 0.0, 0.0); glColor3f(0.0, 0.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluOrtho2D(-3000.0, 3000.0, -3000.0, 3000.0);}void display(void){ glClear(GL_COLOR_BUFFER_BIT); // draw the bg glColor3f(1.0, 0.0, 0.0); glBegin(GL_POLYGON); // this is once again reverted ...poor coding probably! glColor4fb(pmap->bgColorBottom.red,pmap->bgColorBottom.green,pmap->bgColorBottom.blue,pmap->bgColorBottom.alpha); glVertex2f(pmap->leftoffs, pmap->topoffs); glVertex2f(pmap->rightoffs, pmap->topoffs); glColor4fb(pmap->bgColorTop.red,pmap->bgColorTop.green,pmap->bgColorTop.blue,pmap->bgColorTop.alpha); glVertex2f(pmap->rightoffs, pmap->bottomoffs); glVertex2f(pmap->leftoffs, pmap->bottomoffs); glEnd(); glColor3f(0.0, 0.0, 1.0); // texture stuff was allocated on init and on map read glBegin(GL_TRIANGLES); for(int i = 0;i<pmap->polygonCount;i++){ for(int m = 0;m < 3;m++){ //color glColor4fb(pmap->polygon[i].vertex[m].color.red,pmap->polygon[i].vertex[m].color.green,pmap->polygon[i].vertex[m].color.blue,pmap->polygon[i].vertex[m].color.alpha); // texture // position: the y axis is reversed in the map coords glVertex3f(pmap->polygon[i].vertex[m].x,-1.0*pmap->polygon[i].vertex[m].y,0.0); } } glEnd(); glScalef(sfactor,sfactor,sfactor); glTranslatef(mx,my,0.0); sfactor = 1.0; mx = 0; my = 0; glutSwapBuffers(); glFlush();}// converts from 0-255 notation to opengl's [0,1]void glColor4fb(float r ,float g ,float b,float a){ glColor4f(r/255.0,g/255.0,b/255,a/255.0);}void keyboard(unsigned char key, int x, int y) { switch(key){ case 'q': sfactor = 1.1; break; case 'e': sfactor = 0.9; break; case 'w': my = -10.0; break; case 's': my = 10.0; break; case 'a': mx = 10.0; break; case 'd': mx = -10.0; break; } // re paint glutPostRedisplay();}
someone as information on freeimage.h? because I don't have it.
Edit: I discovered the lines were caused by the textures bleeding onto the other side, like they are wrapping despite GL_CLAMP being set. Scenery that is transparent along the opposite border doesn't have this issue.
glBegin(GL_QUADS);  glColor4fb(pmap->prop[i].color.red,          pmap->prop[i].color.green,  pmap->prop[i].color.blue         pmap->prop[i].alpha);  glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0);  glTexCoord2f(0.0, 1.0); glVertex2f(0.0, pmap->prop[i].height);  glTexCoord2f(1.0, 1.0); glVertex2f(pmap->prop[i].width, pmap->prop[i].height);  glTexCoord2f(1.0, 0.0); glVertex2f(pmap->prop[i].width, 0.0);glEnd();