squizm

Members
  • Content count

    17
  • Joined

  • Last visited

Community Reputation

100 Neutral

About squizm

  • Rank
    Member
  1. Hello, I'm working on a port of a free Print'n'Play game from BoardGameGeek called ZombiePlague. Its my first full game project so be easy on me. I'm having trouble saving a vector or a class and reading it back. To begin, here is the class I'm looking to write to a file: [code] enum Facing{ NORTH = 0, EAST = 1, SOUTH = 2, WEST = 3 }; enum GamePieceType{ CHARACTER = 0x01, ZOMBIE = 0x02, BARACADE = 0x04 }; class GamePiece { public: int tileX; int tileY; int facing; int actionPoints; unsigned char _type; GamePiece() {facing = NORTH; actionPoints = 2; _type = ZOMBIE;}; GamePiece(int x, int y, int direction, int ap, unsigned char type) {tileX = x; tileY = y; facing = direction; actionPoints = ap; _type = type;}; }; [/code] In my game, I keep the game pieces in an array as that there could be more pieces added every turn. What would be the best method to write this vector to a file and read it back? I've had multiple attempts and none have been successful. Any web reference or feedback appreciated. Here is what I've tried without success: [code] void loadLevel() { fstream levelData ("level.dat", ios::in | ios::binary); for(int i = 0; i < (int)gamePieces.size(); i++) levelData.read((char *)&gamePieces.at(i), sizeof(GamePiece)); }; void saveLevel() { fstream levelData("level.dat", ios::out | ios::binary); for(int i = 0; i < (int)gamePieces.size(); i++) levelData.write((char *)gamePieces.at(i), sizeof(GamePiece)); }; [/code] Here is a pic of the prototype I have so far: [img]http://i.imgur.com/LFUSX.png[/img]
  2. Measuring distance on Hex grid

    [quote name='alvaro' timestamp='1316198229' post='4862547'] I'll give it a try: [code]public int myDistance(int x1, int y1, int x2, int y2) { int sane_y1 = y1 - x1/2; int sane_y2 = y2 - x2/2; int dx = x2 - x1; int dy = sane_y2 - sane_y1; return dx*dy > 0 ? Math.abs(dx+dy) : Math.max(Math.abs(dx), Math.abs(dy)); } [/code] [/quote] Fantastic! Thank you very much.
  3. Hello, I'm trying to figure out how to measure the distance between two hexes in a map. I can't seem to wrap my head around what to do for my setup. I've tried to follow [url="http://www-cs-students.stanford.edu/~amitp/Articles/HexLOS.html"]http://www-cs-studen...les/HexLOS.html[/url] but it doesn't give me the desired results. Here is a screenshot of my setup: [img]http://i.imgur.com/WryCC.jpg[/img] As you can see, with a "range" of 2 the following tiles should NOT have been highlighted in yellow: 3, 3 4, 3 6, 3 7, 3 3, 7 7, 7 Here is my code: [code] public int myDistance(int x1, int y1, int x2, int y2) { int dist = 0; int dx, dy, dt = 0; dx = Math.abs(x1 - x2); dy = Math.abs(y1 - y2); dt = Math.abs(dx-dy); dist = Math.max(dx, dy); dist = Math.max(dist, dt); return dist; } [/code] Any assistance would be greatly appreciate!
  4. [quote name='V-man' timestamp='1305561315' post='4811474'] [url="http://www.opengl.org/wiki/FAQ#Memory_Usage"]http://www.opengl.or...AQ#Memory_Usage[/url] [/quote] ...interesting. Thank you for the link. I'll put this on the back burner for now and address it again if it starts to cause out of memory errors. Thanks all!
  5. [quote] My bad, i meant [color="#660066"][font="CourierNew, monospace"][size="2"]GetHeight()[/size][/font][/color][color="#660066"][size="2"][font="Arial"], Also what does [/font][/size][/color][color="#1C2837"][size="2"][color="#000000"][font="CourierNew, monospace"]hexMap[/font][/color][color="#666600"][font="CourierNew, monospace"][[/font][/color][color="#000000"][font="CourierNew, monospace"]x[/font][/color][color="#666600"][font="CourierNew, monospace"]][[/font][/color][color="#000000"][font="CourierNew, monospace"]y[/font][/color][color="#666600"][font="CourierNew, monospace"]].[/font][/color][color="#000000"][font="CourierNew, monospace"]drawRenderMode[/font][/color][color="#666600"][font="CourierNew, monospace"]()[/font][font="Arial"] do?[/font][/color][/size][/color] The posted code looks fine, the problem is where stuff is created and destroyed. No new-statements : good for you! [/quote] PerlinNoise.cpp [code] double PerlinNoise::GetHeight(double x, double y) const { return amplitude * Total(x, y); } double PerlinNoise::Total(double i, double j) const { //properties of one octave (changing each loop) double t = 0.0f; double _amplitude = 1; double freq = frequency; for(int k = 0; k < octaves; k++) { t += GetValue(j * freq + randomseed, i * freq + randomseed) * _amplitude; _amplitude *= persistence; freq *= 2; } return t; } double PerlinNoise::GetValue(double x, double y) const { int Xint = (int)x; int Yint = (int)y; double Xfrac = x - Xint; double Yfrac = y - Yint; //noise values double n01 = Noise(Xint-1, Yint-1); double n02 = Noise(Xint+1, Yint-1); double n03 = Noise(Xint-1, Yint+1); double n04 = Noise(Xint+1, Yint+1); double n05 = Noise(Xint-1, Yint); double n06 = Noise(Xint+1, Yint); double n07 = Noise(Xint, Yint-1); double n08 = Noise(Xint, Yint+1); double n09 = Noise(Xint, Yint); double n12 = Noise(Xint+2, Yint-1); double n14 = Noise(Xint+2, Yint+1); double n16 = Noise(Xint+2, Yint); double n23 = Noise(Xint-1, Yint+2); double n24 = Noise(Xint+1, Yint+2); double n28 = Noise(Xint, Yint+2); double n34 = Noise(Xint+2, Yint+2); //find the noise values of the four corners double x0y0 = 0.0625*(n01+n02+n03+n04) + 0.125*(n05+n06+n07+n08) + 0.25*(n09); double x1y0 = 0.0625*(n07+n12+n08+n14) + 0.125*(n09+n16+n02+n04) + 0.25*(n06); double x0y1 = 0.0625*(n05+n06+n23+n24) + 0.125*(n03+n04+n09+n28) + 0.25*(n08); double x1y1 = 0.0625*(n09+n16+n28+n34) + 0.125*(n08+n14+n06+n24) + 0.25*(n04); //interpolate between those values according to the x and y fractions double v1 = Interpolate(x0y0, x1y0, Xfrac); //interpolate in x direction (y) double v2 = Interpolate(x0y1, x1y1, Xfrac); //interpolate in x direction (y+1) double fin = Interpolate(v1, v2, Yfrac); //interpolate in y direction return fin; } double PerlinNoise::Interpolate(double x, double y, double a) const { double negA = 1.0 - a; double negASqr = negA * negA; double fac1 = 3.0 * (negASqr) - 2.0 * (negASqr * negA); double aSqr = a * a; double fac2 = 3.0 * aSqr - 2.0 * (aSqr * a); return x * fac1 + y * fac2; //add the weighted factors } double PerlinNoise::Noise(int x, int y) const { int n = x + y * 57; n = (n << 13) ^ n; int t = (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff; return 1.0 - double(t) * 0.931322574615478515625e-9;/// 1073741824.0); } [/code] HexNode.cpp [code] void HexNode::drawRenderMode() { glBindTexture(GL_TEXTURE_2D, terrainType); // Top Hexagon glBegin(GL_TRIANGLE_FAN); glNormal3d(0, 1, 0); glTexCoord2f(0.5f, 0.5f); glVertex3f( 0.0f, 0.0f, hexHeight ); //center glTexCoord2f(1.0f, 0.5f); glVertex3f( 1.0f, 0.0f, hexHeight ); //right glTexCoord2f(0.75f, 1.0f); glVertex3f( 0.5f, 1.0f, hexHeight ); //top right glTexCoord2f(0.25f, 1.0f); glVertex3f( -0.5f, 1.0f, hexHeight ); //Top left glTexCoord2f(0.0f, 0.5f); glVertex3f( -1.0f, 0.0f, hexHeight ); //left glTexCoord2f(0.25f, 0.0f); glVertex3f( -0.5f, -1.0f, hexHeight ); //bottom left glTexCoord2f(0.75f, 0.0f); glVertex3f( 0.5f, -1.0f, hexHeight ); //bottom right glTexCoord2f(1.0f, 0.5f); glVertex3f( 1.0f, 0.0f, hexHeight ); //right glEnd(); glBindTexture(GL_TEXTURE_2D, TEX_ROCK); // bottom Hexagon glBegin(GL_TRIANGLE_FAN); glNormal3d(0, -1, 0); glTexCoord2f(0.5f, 0.5f); glVertex3f( 0.0f, 0.0f, 0.0f ); //center glTexCoord2f(1.0f, 0.5f); glVertex3f( 1.0f, 0.0f, 0.0f ); //right glTexCoord2f(0.75f, 1.0f); glVertex3f( 0.5f, 1.0f, 0.0f ); //top right glTexCoord2f(0.25f, 1.0f); glVertex3f( -0.5f, 1.0f, 0.0f ); //Top left glTexCoord2f(0.0f, 0.5f); glVertex3f( -1.0f, 0.0f, 0.0f ); //left glTexCoord2f(0.25f, 0.0f); glVertex3f( -0.5f, -1.0f, 0.0f ); //bottom left glTexCoord2f(0.75f, 0.0f); glVertex3f( 0.5f, -1.0f, 0.0f ); //bottom right glTexCoord2f(1.0f, 0.5f); glVertex3f( 1.0f, 0.0f, 0.0f ); //right glEnd(); float vertices[3][3]; glBegin(GL_QUADS); vertices[0][0] = 1.0f; vertices[0][1] = 0.0f; vertices[0][2] = hexHeight; vertices[1][0] = 0.5f; vertices[1][1] = 1.0f; vertices[1][2] = hexHeight; vertices[2][0] = 0.5f; vertices[2][1] = 1.0f; vertices[2][2] = 0.0f; GameUtils::getInstance()->calcNormal(vertices, normal); glNormal3d(normal[0], normal[1], normal[2]); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 0.0f, hexHeight ); //right vertex glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.5f, 1.0f, hexHeight ); glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.5f, 1.0f, 0.0f ); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 0.0f, 0.0f ); vertices[0][0] = 0.5f; vertices[0][1] = 1.0f; vertices[0][2] = hexHeight; vertices[1][0] = -0.5f; vertices[1][1] = 1.0f; vertices[1][2] = hexHeight; vertices[2][0] = -0.5f; vertices[2][1] = 1.0f; vertices[2][2] = 0.0f; GameUtils::getInstance()->calcNormal(vertices, normal); glNormal3d(normal[0], normal[1], normal[2]); glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.5f, 1.0f, hexHeight ); // top right vertex glTexCoord2f(0.0f, 0.0f); glVertex3f( -0.5f, 1.0f, hexHeight ); glTexCoord2f(0.0f, 1.0f); glVertex3f( -0.5f, 1.0f, 0.0f ); glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.5f, 1.0f, 0.0f ); vertices[0][0] = -0.5f; vertices[0][1] = 1.0f; vertices[0][2] = hexHeight; vertices[1][0] = -1.0f; vertices[1][1] = 0.0f; vertices[1][2] = hexHeight; vertices[2][0] = -1.0f; vertices[2][1] = 0.0f; vertices[2][2] = 0.0f; GameUtils::getInstance()->calcNormal(vertices, normal); glNormal3d(normal[0], normal[1], normal[2]); glTexCoord2f(1.0f, 0.0f); glVertex3f( -0.5f, 1.0f, hexHeight ); // top left vertex glTexCoord2f(0.0f, 0.0f); glVertex3f( -1.0f, 0.0f, hexHeight ); glTexCoord2f(0.0f, 1.0f); glVertex3f( -1.0f, 0.0f, 0.0f ); glTexCoord2f(1.0f, 1.0f); glVertex3f( -0.5f, 1.0f, 0.0f ); vertices[0][0] = -1.0f; vertices[0][1] = 0.0f; vertices[0][2] = hexHeight; vertices[1][0] = -0.5f; vertices[1][1] = -1.0f; vertices[1][2] = hexHeight; vertices[2][0] = -0.5f; vertices[2][1] = 0.0f; vertices[2][2] = 0.0f; GameUtils::getInstance()->calcNormal(vertices, normal); glNormal3d(normal[0], normal[1], normal[2]); glTexCoord2f(1.0f, 0.0f); glVertex3f( -1.0f, 0.0f, hexHeight ); // left vertex glTexCoord2f(0.0f, 0.0f); glVertex3f( -0.5f, -1.0f, hexHeight ); glTexCoord2f(0.0f, 1.0f); glVertex3f( -0.5f, -1.0f, 0.0f ); glTexCoord2f(1.0f, 1.0f); glVertex3f( -1.0f, 0.0f, 0.0f ); vertices[0][0] = -0.5f; vertices[0][1] = -1.0f; vertices[0][2] = hexHeight; vertices[1][0] = 0.5f; vertices[1][1] = -1.0f; vertices[1][2] = hexHeight; vertices[2][0] = 0.5f; vertices[2][1] = -1.0f; vertices[2][2] = 0.0f; GameUtils::getInstance()->calcNormal(vertices, normal); glNormal3d(normal[0], normal[1], normal[2]); glTexCoord2f(1.0f, 0.0f); glVertex3f( -0.5f, -1.0f, hexHeight ); // bottom left vertex glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.5f, -1.0f, hexHeight ); glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.5f, -1.0f, 0.0f ); glTexCoord2f(1.0f, 1.0f); glVertex3f( -0.5f, -1.0f, 0.0f ); vertices[0][0] = 0.5f; vertices[0][1] = -1.0f; vertices[0][2] = hexHeight; vertices[1][0] = 1.0f; vertices[1][1] = 0.0f; vertices[1][2] = hexHeight; vertices[2][0] = 1.0f; vertices[2][1] = 0.0f; vertices[2][2] = 0.0f; GameUtils::getInstance()->calcNormal(vertices, normal); glNormal3d(normal[0], normal[1], normal[2]); glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.5f, -1.0f, hexHeight ); // bottom right vertex glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, 0.0f, hexHeight ); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 0.0f, 0.0f ); glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.5f, -1.0f, 0.0f ); glEnd(); if(character.name != "null") { glColor3f(1.0f, 0.0f, 0.0f); glDisable(GL_TEXTURE_2D); glTranslatef(0.0f, 0.0f, 1.0f); character.drawRenderMode(); glTranslatef(0.0f, 0.0f, -1.0f); glEnable(GL_TEXTURE_2D); glLineWidth(3.0f); glBegin(GL_LINE_STRIP); glVertex3f( 1.0f, 0.0f, hexHeight ); //right glVertex3f( 0.5f, 1.0f, hexHeight ); //top right glVertex3f( -0.5f, 1.0f, hexHeight ); //Top left glVertex3f( -1.0f, 0.0f, hexHeight ); //left glVertex3f( -0.5f, -1.0f, hexHeight ); //bottom left glVertex3f( 0.5f, -1.0f, hexHeight ); //bottom right glVertex3f( 1.0f, 0.0f, hexHeight ); glEnd(); glColor3f(1.0f, 1.0f, 1.0f); } } [/code] GameUtils [code] GLvoid GameUtils::calcNormal(float v[3][3], float normal[3]) { float v1[3],v2[3]; // Vector 1 (x,y,z) & Vector 2 (x,y,z) static const int x = 0; // Define X Coord static const int y = 1; // Define Y Coord static const int z = 2; // Define Z Coord // Finds The Vector Between 2 Points By Subtracting // The x,y,z Coordinates From One Point To Another. // Calculate The Vector From Point 1 To Point 0 v1[x] = v[0][x] - v[1][x]; // Vector 1.x=Vertex[0].x-Vertex[1].x v1[y] = v[0][y] - v[1][y]; // Vector 1.y=Vertex[0].y-Vertex[1].y v1[z] = v[0][z] - v[1][z]; // Vector 1.z=Vertex[0].y-Vertex[1].z // Calculate The Vector From Point 2 To Point 1 v2[x] = v[1][x] - v[2][x]; // Vector 2.x=Vertex[0].x-Vertex[1].x v2[y] = v[1][y] - v[2][y]; // Vector 2.y=Vertex[0].y-Vertex[1].y v2[z] = v[1][z] - v[2][z]; // Vector 2.z=Vertex[0].z-Vertex[1].z // Compute The Cross Product To Give Us A Surface Normal normal[x] = v1[y]*v2[z] - v1[z]*v2[y]; // Cross Product For Y - Z normal[y] = v1[z]*v2[x] - v1[x]*v2[z]; // Cross Product For X - Z normal[z] = v1[x]*v2[y] - v1[y]*v2[x]; // Cross Product For X - Y normalize(normal); // Normalize The Vectors } GLvoid GameUtils::normalize(float vector[3]) { float length; // Holds Unit Length // Calculates The Length Of The Vector length = (float)sqrt((vector[0]*vector[0]) + (vector[1]*vector[1]) + (vector[2]*vector[2])); if(length == 0.0f) // Prevents Divide By 0 Error By Providing length = 1.0f; // An Acceptable Value For Vectors To Close To 0. vector[0] /= length; // Dividing Each Element By vector[1] /= length; // The Length Results In A vector[2] /= length; // Unit Normal Vector. } [/code]
  6. [quote name='SuperVGA' timestamp='1305552668' post='4811416'] Hi! What does [font="CourierNew, monospace"][size="2"]createNewMap()[/size][/font][size="2"][font="Arial"] do?[/font][/size] [size="2"] [/size] [size="2"][font="Arial"]If it contains a "new" statement, remember to "delete" when you're done with the object.[/font][/size] [size="2"][font="Arial"]I advice to avoid using new unless you absolutely have to, -there's typically an easier way.[/font][/size] [/quote] createNewMap is a boolean that is used to determine if I need to get new perlin noise values used for the heightmap. There is no 'new' statement used.
  7. Hello, I'm having some trouble with a function that creates/recreates my display list. This is called once at the beginning of the application and once every time a different terrain hex is selected. However, every time this function runs, the application eats up ~2400k more. Each time I run the function I delete the old display list and create a new one using these three lines: [code] glDeleteLists(terrainList, 1); terrainList = glGenLists(1); glNewList(terrainList, GL_COMPILE_AND_EXECUTE); [/code] Is this the correct method to do this? Or is this the culprit? Here is the full function: [code] void PlayScreen::generateTerrainList() { for(int i = 0; i < tilesX; i++) { for(int j = 0; j < tilesY; j++) { heightMap[i][j] = perlin.GetHeight(i, j); if(createNewMap) hexMap[i][j] = HexNode(i+100, 0, j+100); } } bool even = true; glDeleteLists(terrainList, 1); terrainList = glGenLists(1); glNewList(terrainList, GL_COMPILE_AND_EXECUTE); for( int x = 0; x < tilesX; x++ ) { for( int y = 0; y < tilesY; y++ ) { glMatrixMode(GL_MODELVIEW); glShadeModel(GL_SMOOTH); glPushMatrix(); glEnable(GL_COLOR_MATERIAL); int height = heightMap[x][y]; if(height > 1.0f) { height = 4.0f; hexMap[x][y].terrainType = TEX_DIRT; hexMap[x][y].hexHeight = height; glColor3f(1.0f, 1.0f, 1.0f); } else if(height > 0.3f) { height = 3.0f; hexMap[x][y].terrainType = TEX_DIRT; hexMap[x][y].hexHeight = height; glColor3f(0.8f, 0.8f, 0.8f); } else if (height > -0.5) { height = 2.0f; hexMap[x][y].terrainType = TEX_DIRT; hexMap[x][y].hexHeight = height; glColor3f(0.6f, 0.6f, 0.6f); } else { height = 1.0f; hexMap[x][y].terrainType = TEX_DIRT; glColor3f(0.4f, 0.4f, 0.4f); } glTranslatef(0, y*2, height); hexMap[x][y].drawRenderMode(); //selected Hex if(selectedX == x && selectedY == y) { glTranslatef(0.0f, 0.0f, height); props[x][y].drawSelectBox(); glTranslatef(0.0f, 0.0f, -height); } glPopMatrix(); } if(even) { glTranslatef(1.5, -1, 0); even = false; } else { glTranslatef(1.5, 1, 0); even = true; } } glEndList(); createNewMap = false; } [/code]
  8. I'm rendering multiple hexagons and am having an issue where the hexagons in the distance have an odd blue tinge to them. Here is a screenshot: [url="http://imgur.com/JH15X"]http://imgur.com/JH15X[/url] Any idea why this is happening?
  9. [quote name='Brother Bob' timestamp='1303935405' post='4803707'] [quote name='jyk' timestamp='1303935063' post='4803706'] I'm not sure how GLUT works with respect to creating the OpenGL context - is the context created in glutInit(), or in (e.g.) glutInitDisplayMode()? I'm sure someone else will know the answer to that question, but meanwhile you might check the docs and see if you can determine it yourself. (The OpenGL initialization code needs to be run *after* a valid context is created; otherwise, run-time errors can occur.) [/quote] The rendering context is created in glutCreateWindow. [/quote] That was the issue. I created a function to load my textures after the glutCreateWindow call and it works like a champ. Thanks again for all your help.
  10. [quote name='jyk' timestamp='1303933997' post='4803696'] Can you narrow it down further to the line of code that's actually causing the violation? Also, are you creating the textures after a valid OpenGL context has been created? [/quote] the function I posted above (SOIL_internal_create_ogl_texture) appears to run just fine until the following line: [code] if( (query_NPOT_capability() == SOIL_CAPABILITY_NONE) && !(flags & SOIL_FLAG_TEXTURE_RECTANGLE) ) { /* add in the POT flag */ flags |= SOIL_FLAG_POWER_OF_TWO; } [/code] Stepping into that function is opens 'strstr.asm' and gets the violation on the exact line: [code] mov al,[edi] ; al is next char from str1 [/code] As for the openGL context, I am pretty new to openGL and completely self taught. The loading of the textures is down in my custom initGL() function: [code] GLvoid initGL(GLsizei width, GLsizei height) { glViewport(0,0,width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, (GLfloat)width / (GLfloat)height, 0.1f, 200.0f); glShadeModel(GL_SMOOTH); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glEnable(GL_PERSPECTIVE_CORRECTION_HINT); glEnable(GL_TEXTURE_2D); glEnable(GL_LIGHTING); //Create Screens screens[MENU_SCREEN] = &menuScreen; screens[GAME_SCREEN] = &playScreen; //create Textures GLuint tex_Dirt; tex_Dirt = SOIL_load_OGL_texture("dirt.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS); } [/code] and the main function looks like this: [code] int main(int argc, char* argv[]) { // Init glut glutInit(&argc, argv); initGL(windowWidth, windowHeight); glutInitDisplayMode(GLUT_DOUBLE); int windowID = glutCreateWindow("myGame"); glutReshapeWindow(windowWidth, windowHeight); glutDisplayFunc(drawScene); glutKeyboardFunc(keyboardCB); glutKeyboardUpFunc(keyboardUpCB); glutSpecialFunc(keyboardSpecialCB); glutSpecialUpFunc(keyboardSpecialUpCB); glutTimerFunc(1, timerLoop, 0); glutMouseFunc(updateMouse); glutMotionFunc(mouseMove); glutPassiveMotionFunc(mouseMove); glutMainLoop(); } [/code]
  11. HELP! I'm attempting to use SOIL to load the JPGs for my openGL program. I'm compiled my own SOIL.lib and included it in the Visual Studio 2010 additional dependencies, and copy and included SOIL.h. However, at runtime I get an access violation from the following line: [code] tex_Dirt = SOIL_load_OGL_texture("dirt.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS); [/code] Anyone ever run into this before? What other information can I provide to help diagnose this? EDIT: I set a break point on that line and followed it through SOIL.c. Turns out it causes the access violation at the following line: [code] /* OK, make it a texture! */ tex_id = SOIL_internal_create_OGL_texture( img, width, height, channels, reuse_texture_ID, flags, GL_TEXTURE_2D, GL_TEXTURE_2D, GL_MAX_TEXTURE_SIZE ); [/code]
  12. I've just read through your link V-man and found this interesting tidbit: "[font=sans-serif][size=2]A modern OpenGL program should not use the selection buffer or feedback mode. These are not 3D graphics rendering features yet they have been added to GL since version 1.0. Selection and feedback runs in software (CPU side). On some implementations, when used along with VBOs, it has been reported that performance is lousy."[/size][/font] [font=sans-serif][size=2] [/size][/font] [font=sans-serif][size=2]That being said, I started to look into color picking as my method of selection. I found a good article on one implementation here:[/size][/font] [font=sans-serif][size=2] [/size][/font] [font=sans-serif][size=2][url="http://gpwiki.org/index.php/OpenGL_Selection_Using_Unique_Color_IDs"]Color Picking[/url] [/size][/font] This example created a separate class that handles the color assignment. Using that idea, I can build on the class to contain all the information and references I need for my game. I'm going to try this method and see where I get. Thank for your help!
  13. [quote name='V-man' timestamp='1301927277' post='4794212'] I'm not sure what you are asking for. Are you asking how picking an object can be done with a mouse click? [url="http://www.opengl.org/wiki/Common_Mistakes#Selection_and_Picking_and_Feedback_Mode"]http://www.opengl.or...d_Feedback_Mode[/url] [/quote] Sorry for not being more clear. Perhaps I'll explain the end result I'm looking for... I'd like to be able to click on a hexagon and have the information about that hexagon appear. For example, when the user clicks on a grass hex it would display the following: Hex number (row, column) Hex type (rock, dirt, grass, water) Any units on that tile (an array of a class called Unit) I have read that picking can provide you a 'name' for the selected hexagon. What is an effective method of linking the 'name' with the other information?
  14. I've created a terrain editor for a strategy game I'm creating. You can find the alpha here: [url="http://db.tt/x1Ep1XZ%20"]ThoriumBREED terrain editor[/url] Now that you can see what I'm going for, how do I go about linking each drawn hexagon to another class that contains data about that hexagon? For example, the mountain hexagons will provide a defensive bonus to the units occupying that hex. This is my first game project so I'm just not sure of the way this is usually implemented. how do I link a hexagon to a class containing information about that hexagon (terrain type, units placed there, etc).
  15. [quote name='Faireth' timestamp='1301071836' post='4790420'] in regards to: [quote name='zerothrillz' timestamp='1301018389' post='4790209'] let box := an axis aligned box encompassing the whole of the shape [/quote] is box a 3D shape with its own vertices? given the following vertexes, could you perhaps clarify? [code] glVertex3f( 0.0f, 0.0f, 0.0f ); //center glVertex3f( 1.0f, 0.0f, 0.0f ); //right glVertex3f( 0.5f, 1.0f, 0.0f ); //top right glVertex3f( -0.5f, 1.0f, 0.0f ); //Top left glVertex3f( -1.0f, 0.0f, 0.0f ); //left glVertex3f( -0.5f, -1.0f, 0.0f ); //bottom left glVertex3f( 0.5f, -1.0f, 0.0f ); //bottom right glVertex3f( 1.0f, 0.0f, 0.0f ); //right [/code] Thank you very much for the help. [/quote] Got it thanks to zerothrillz explanation: [code] glTexCoord2f(0.5f, 0.5f); glVertex3f( 0.0f, 0.0f, 0.0f ); //center glTexCoord2f(1.0f, 0.5f); glVertex3f( 1.0f, 0.0f, 0.0f ); //right glTexCoord2f(0.75f, 1.0f); glVertex3f( 0.5f, 1.0f, 0.0f ); //top right glTexCoord2f(0.25f, 1.0f); glVertex3f( -0.5f, 1.0f, 0.0f ); //Top left glTexCoord2f(0.0f, 0.5f); glVertex3f( -1.0f, 0.0f, 0.0f ); //left glTexCoord2f(0.25f, 0.0f); glVertex3f( -0.5f, -1.0f, 0.0f ); //bottom left glTexCoord2f(0.75f, 0.0f); glVertex3f( 0.5f, -1.0f, 0.0f ); //bottom right glTexCoord2f(1.0f, 0.5f); glVertex3f( 1.0f, 0.0f, 0.0f ); //right [/code] Thank you very much!