• Content count

  • Joined

  • Last visited

Community Reputation

116 Neutral

About Verideth

  • Rank

Personal Information

  • Interests
  1. I've recently been working on a voxel engine, but I've ran into a small problem. My voxel engine chunks, will not draw for some odd reason. I've been having trouble with this for a few hours now. I've debugged in RenderDoc, everything seems fine. I'm starting to think somethings wrong with how I setup my functions. Here is the code:   void Chunk::createMesh() { int i = 0; this->shader.loadShader("chunk.vs", "chunk.fs"); for (int x = 0; x < CHUNK_SIZE; x++) { for (int y = 0; y < CHUNK_HEIGHT; y++) { for (int z = 0; z < CHUNK_SIZE; z++) { GLuint currentBlock = this->blockCur[x][y][z]; this->vertex[i++] = byte4(x, y, z, currentBlock); this->vertex[i++] = byte4(x, y, z + 1, currentBlock); this->vertex[i++] = byte4(x, y + 1, z, currentBlock); this->vertex[i++] = byte4(x, y + 1, z, currentBlock); this->vertex[i++] = byte4(x, y, z + 1, currentBlock); this->vertex[i++] = byte4(x, y + 1, z + 1, currentBlock); // View from positive x this->vertex[i++] = byte4(x + 1, y, z, currentBlock); this->vertex[i++] = byte4(x + 1, y + 1, z, currentBlock); this->vertex[i++] = byte4(x + 1, y, z + 1, currentBlock); this->vertex[i++] = byte4(x + 1, y + 1, z, currentBlock); this->vertex[i++] = byte4(x + 1, y + 1, z + 1, currentBlock); this->vertex[i++] = byte4(x + 1, y, z + 1, currentBlock); currentBlock++; } } } this->elements = i; glGenVertexArrays(1, &this->vao); glBindVertexArray(this->vao); glGenBuffers(1, &this->vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, this->elements * sizeof(this->vertex), this->vertex, GL_STATIC_DRAW); glGenBuffers(1, &cubeColor); glBindBuffer(GL_ARRAY_BUFFER, cubeColor); glBufferData(GL_ARRAY_BUFFER, sizeof(color), color, GL_STATIC_DRAW); this->attribCoord3dChunk = glGetAttribLocation(this->shader.program, "coord3d"); this->attribMVPChunk = glGetUniformLocation(this->shader.program, "mvp"); this->attribColor = glGetUniformLocation(this->shader.program, "f_color"); if (this->attribCoord3dChunk < 0) { std::cout << "attribCoord3dChunk was negative!" << std::endl; } std::cout << this->attribMVPChunk << std::endl; glBindBuffer(GL_ARRAY_BUFFER, this->vbo); glVertexAttribPointer( this->attribCoord3dChunk, // attribute 3, // number of elements per vertex, here (R,G,B) GL_FLOAT, // the type of each element GL_FALSE, // take our values as-is 0, // no extra data between each position (GLvoid*)0 // offset of first element ); glEnableVertexAttribArray(this->attribCoord3dChunk); glBindBuffer(GL_ARRAY_BUFFER, this->chunkColor); glVertexAttribPointer( this->attribColor, // attribute 3, // number of elements per vertex, here (x,y,z) GL_FLOAT, // the type of each element GL_FALSE, // take our values as-is 0, // no extra data between each position (GLvoid*)0 // offset of first element ); glEnableVertexAttribArray(this->attribColor); glBindVertexArray(0); this->loaded = true; } void Chunk::render() { glBindVertexArray(this->vao); glEnableVertexAttribArray(this->attribCoord3dChunk); glEnableVertexAttribArray(this->attribColor); model = glm::translate(glm::mat4(1.0f), glm::vec3(1, 1, 1)); glm::mat4 mvp = gameManager->projection * gameManager->view * model; glUniformMatrix4fv(this->attribMVPChunk, 1, GL_FALSE, glm::value_ptr(mvp)); glBindBuffer(GL_ARRAY_BUFFER, this->vbo); glDrawArrays(GL_TRIANGLES, 0, this->elements); glDisableVertexAttribArray(this->attribCoord3dChunk); glDisableVertexAttribArray(this->attribColor); glBindVertexArray(0); }   Where byte4's typedef is   typedef glm::tvec4<GLbyte> byte4;   I call createMesh once, before the render loop. And I also call render, every frame.   Thanks!! All help is appreciated :)
  2. Book suggestions for C++ 2D Game Programming

    Hey! I've read tons of books on OpenGL, and one for 2D games, and lots of math books. Honestly though, if you want my HONEST opinion, ditch the OpenGL book idea. Most of them will be 3D, not 2D. Which based on what you've said, you do not want. Books I recommend that are good: (crash course on vector math for 2 games): (SFML game development):   Good luck on your journey!! :)
  3. I've recently gotten into OpenGL game development, and decided to make my game BSP map based. I've been following this guys Q3 map specs (quake 3)     Its been tough, but I finally got it to render. My problem persists in that its drawing some weird "pyramid" type amodel. Which is definitely not what I'm looking for. I want it to be drawing the map.   It should be a room with just a ramp. Nothing even remotely close to that.   Here is my header file for the BSP renderer       #pragma once          // Include standard headers     #include <stdio.h>     #include <stdlib.h>     // Include GLEW     #include <GL/glew.h>          // Include GLM     #include <glm/glm.hpp>     #include <glm/gtc/matrix_transform.hpp>     #include <vector>          #define FACE_POLYGON 1          enum LUMPS     {     LUMP_ENTITIES = 0, // Game-related object descriptions     LUMP_TEXTURE, // Surface descriptions.     LUMP_PLANES,   // Planes used by map geometry.     LUMP_NODES, // BSP tree nodes.     LUMP_LEAFS, // BSP tree leaves.     LUMP_LEAFFACES, // Lists of face indices, one list per leaf.     LUMP_LEAFBRUSHES, // Lists of brush indices, one list per leaf.     LUMP_MODELS, // Descriptions of rigid world geometry in map.     LUMP_BRUSHES, // Convex polyhedra used to describe solid space.     LUMP_BRUSHSIDES, // Brush surfaces.     LUMP_VERTEXES, // Vertices used to describe faces.     LUMP_INDICES, // Lists of offsets, one list per mesh.     LUMP_EFFECTS, // List of special map effects.     LUMP_FACES, // Surface geometry.     LUMP_LIGHTMAPS, // Packed lightmap data.     LUMP_LIGHTVOLS, // Local illumination data.     LUMP_VISDATA, // Cluster-cluster visibility data.     LUMP_ALL_DATA // A constant to store the number of lumps     };          struct Lump     {     int offset;     int length;     };          struct Header     {     char magic[4]; // Magic number.Always "IBSP".     int version; // Version number. 0x2e for the BSP files distributed with Quake 3.     };          struct Faces     {     int textureID; // The index into the texture array      int effect; // The index for the effects (or -1 = n/a)      int type; // 1=polygon, 2=patch, 3=mesh, 4=billboard      int startVertIndex; // The starting index into this face's first vertex      int numOfVerts; // The number of vertices for this face      int startIndex; // The starting index into the indices array for this face     int numOfIndices; // The number of indices for this face     int lightmapID; // The texture index for the lightmap      int lMapCorner[2]; // The face's lightmap corner in the image      int lMapSize[2]; // The size of the lightmap section      glm::vec3 lMapPos; // The 3D origin of lightmap.      glm::vec3 lMapVecs[2]; // The 3D space for s and t unit vectors.      glm::vec3 vNormal; // The face normal.      int size[2]; // The bezier patch dimensions.      };          struct Vertexes     {     glm::vec3 position; // vertex position     glm::vec2 texCoord; // vertex texture coords     glm::vec2 lightMapCoord; // vertex lightmap coords     glm::vec3 normal; // vertex normal     char color[4]; // vertex color     };          struct Meshverts     {     int offset; // Vertex index offset, relative to first vertex of corresponding face.     };          struct Textures     {     char name[64]; //  Texture name.     int flags; // Surface flags.     int contents; // Content flags.     };          class BSPLoader     {     public:     void LoadBSP(const char* bspFile);     void DrawBSP();     void DrawFaces(int index);          GLuint numOfFaces;     GLuint numOfVertexes;     GLuint numOfIndices;     GLuint numOfTextures;          Faces* pointerFaces;     Vertexes* pointerVertexes;     Meshverts* pointerIndices;     Textures* pointerTextures;     GLuint indiceVbo;     Faces* pFace;          unsigned int maxTextures[1000];          private:     };   Here is my C++ file for that header       // Include standard headers     #include <stdio.h>     #include <stdlib.h>     #include <iostream>     // Include GLEWa     #include <GL/glew.h>          // Include GLM     #include <glm/glm.hpp>     #include <glm/gtc/matrix_transform.hpp>     #include <maps/bspLoader.hpp>     #include <common/texture.hpp>          void BSPLoader::LoadBSP(const char* bspFile)     {     FILE* file = std::fopen(bspFile, "rb");          std::printf("Successfully opened %s\n", bspFile);          Header head = { 0 };     Lump lump[LUMPS::LUMP_ALL_DATA] = { 0 };          // read through header and lump data     std::fread(&head, 1, sizeof(Header), file);     std::fread(lump, LUMPS::LUMP_ALL_DATA, sizeof(Lump), file);          numOfFaces = lump[LUMPS::LUMP_FACES].length / sizeof(Faces); // as specified by the Q3 map specs, divide the length of the lump itself by the sizeof the struct     pointerFaces = new Faces[numOfFaces]; // allocate memory for the faces pointer          numOfVertexes = lump[LUMPS::LUMP_VERTEXES].length / sizeof(Vertexes);     pointerVertexes = new Vertexes[numOfVertexes];          numOfIndices = lump[LUMPS::LUMP_INDICES].length / sizeof(Meshverts);     pointerIndices = new Meshverts[numOfIndices];          std::fseek(file, lump[LUMPS::LUMP_VERTEXES].offset, SEEK_SET);          for (int i = 0; i < numOfVertexes; i++)     {     printf("Vertexes = %i\n", i);          std::fread(&pointerVertexes[0], sizeof(pointerVertexes[0]), numOfVertexes, file);     }          std::fseek(file, lump[LUMPS::LUMP_INDICES].offset, SEEK_SET);     std::fread(&pointerIndices[0], sizeof(pointerIndices), numOfIndices, file);          std::fseek(file, lump[LUMPS::LUMP_FACES].offset, SEEK_SET);     std::fread(&pointerFaces[0], sizeof(pointerFaces), numOfFaces, file);          std::fclose(file);     }          void BSPLoader::DrawFaces(int index)     {     Faces* pFace = &pointerFaces[index];     glVertexPointer(3, GL_FLOAT, sizeof(Vertexes), &(pointerVertexes[pFace->startVertIndex].position));     glEnableClientState(GL_VERTEX_ARRAY);     glDrawElements(GL_TRIANGLES, numOfIndices, GL_UNSIGNED_INT, &(pointerIndices[pFace->startIndex]));     }          void BSPLoader::DrawBSP()     {     for (int i = 0; i < numOfFaces; i++) // go through faces     {     if (pointerFaces[i].type != FACE_POLYGON)     {     continue;     }          DrawFaces(i);     }     }   And finally, here is my main.cpp       // Include standard headers     #include <stdio.h>     #include <stdlib.h>          // Include GLEW     #include <GL/glew.h>          // Include GLFW     #include <glfw/glfw3.h>     GLFWwindow* window;          // Include GLM     #include <glm/glm.hpp>     #include <glm/gtc/matrix_transform.hpp>     using namespace glm;          #include <common/shader.hpp>     #include <common/texture.hpp>     #include <common/controls.hpp>          #include <maps/bspLoader.hpp>          BSPLoader bsp;          int main(void)     {     // Initialise GLFW     if (!glfwInit())     {     fprintf(stderr, "Failed to initialize GLFW\n");     getchar();     return -1;     }          glfwWindowHint(GLFW_SAMPLES, 4);     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);     glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);     glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);          // Open a window and create its OpenGL context     window = glfwCreateWindow(1024, 768, "Vire", NULL, NULL);     if (window == NULL) {     fprintf(stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n");     getchar();     glfwTerminate();     return -1;     }     glfwMakeContextCurrent(window);          // Initialize GLEW     glewExperimental = true; // Needed for core profile     if (glewInit() != GLEW_OK) {     fprintf(stderr, "Failed to initialize GLEW\n");     getchar();     glfwTerminate();     return -1;     }          // Ensure we can capture the escape key being pressed below     glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);     // Hide the mouse and enable unlimited mouvement     glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);          // Set the mouse at the center of the screen     glfwPollEvents();     glfwSetCursorPos(window, 1024 / 2, 768 / 2);          // Dark blue background     glClearColor(0.0f, 0.0f, 0.4f, 0.0f);          // Enable depth test     glEnable(GL_DEPTH_TEST);     // Accept fragment if it closer to the camera than the former one     glDepthFunc(GL_LESS);          // Cull triangles which normal is not towards the camera     glEnable(GL_CULL_FACE);          GLuint VertexArrayID;     glGenVertexArrays(1, &VertexArrayID);     glBindVertexArray(VertexArrayID);          // Create and compile our GLSL program from the shaders     GLuint programID = LoadShaders("TransformVertexShader.vertexshader", "TextureFragmentShader.fragmentshader");          // Get a handle for our "MVP" uniform     GLuint MatrixID = glGetUniformLocation(programID, "MVP");          // Load the texture     GLuint Texture = loadDDS("uvtemplate.DDS");          // Get a handle for our "myTextureSampler" uniform     GLuint TextureID = glGetUniformLocation(programID, "myTextureSampler");          // Our vertices. Tree consecutive floats give a 3D vertex; Three consecutive vertices give a triangle.     // A cube has 6 faces with 2 triangles each, so this makes 6*2=12 triangles, and 12*3 vertices     static const GLfloat g_vertex_buffer_data[] = {     -1.0f,-1.0f,-1.0f,     -1.0f,-1.0f, 1.0f,     -1.0f, 1.0f, 1.0f,     1.0f, 1.0f,-1.0f,     -1.0f,-1.0f,-1.0f,     -1.0f, 1.0f,-1.0f,     1.0f,-1.0f, 1.0f,     -1.0f,-1.0f,-1.0f,     1.0f,-1.0f,-1.0f,     1.0f, 1.0f,-1.0f,     1.0f,-1.0f,-1.0f,     -1.0f,-1.0f,-1.0f,     -1.0f,-1.0f,-1.0f,     -1.0f, 1.0f, 1.0f,     -1.0f, 1.0f,-1.0f,     1.0f,-1.0f, 1.0f,     -1.0f,-1.0f, 1.0f,     -1.0f,-1.0f,-1.0f,     -1.0f, 1.0f, 1.0f,     -1.0f,-1.0f, 1.0f,     1.0f,-1.0f, 1.0f,     1.0f, 1.0f, 1.0f,     1.0f,-1.0f,-1.0f,     1.0f, 1.0f,-1.0f,     1.0f,-1.0f,-1.0f,     1.0f, 1.0f, 1.0f,     1.0f,-1.0f, 1.0f,     1.0f, 1.0f, 1.0f,     1.0f, 1.0f,-1.0f,     -1.0f, 1.0f,-1.0f,     1.0f, 1.0f, 1.0f,     -1.0f, 1.0f,-1.0f,     -1.0f, 1.0f, 1.0f,     1.0f, 1.0f, 1.0f,     -1.0f, 1.0f, 1.0f,     1.0f,-1.0f, 1.0f     };          // Two UV coordinatesfor each vertex. They were created with Blender.     static const GLfloat g_uv_buffer_data[] = {     0.000059f, 0.000004f,     0.000103f, 0.336048f,     0.335973f, 0.335903f,     1.000023f, 0.000013f,     0.667979f, 0.335851f,     0.999958f, 0.336064f,     0.667979f, 0.335851f,     0.336024f, 0.671877f,     0.667969f, 0.671889f,     1.000023f, 0.000013f,     0.668104f, 0.000013f,     0.667979f, 0.335851f,     0.000059f, 0.000004f,     0.335973f, 0.335903f,     0.336098f, 0.000071f,     0.667979f, 0.335851f,     0.335973f, 0.335903f,     0.336024f, 0.671877f,     1.000004f, 0.671847f,     0.999958f, 0.336064f,     0.667979f, 0.335851f,     0.668104f, 0.000013f,     0.335973f, 0.335903f,     0.667979f, 0.335851f,     0.335973f, 0.335903f,     0.668104f, 0.000013f,     0.336098f, 0.000071f,     0.000103f, 0.336048f,     0.000004f, 0.671870f,     0.336024f, 0.671877f,     0.000103f, 0.336048f,     0.336024f, 0.671877f,     0.335973f, 0.335903f,     0.667969f, 0.671889f,     1.000004f, 0.671847f,     0.667979f, 0.335851f     };          GLuint uvbuffer;     glGenBuffers(1, &uvbuffer);     glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);     glBufferData(GL_ARRAY_BUFFER, sizeof(g_uv_buffer_data), g_uv_buffer_data, GL_STATIC_DRAW);          bsp.LoadBSP("maps/Level.bsp");     bsp.DrawBSP();          do     {     // Clear the screen     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);          // Use our shader     glUseProgram(programID);          // Compute the MVP matrix from keyboard and mouse input     computeMatricesFromInputs();     glm::mat4 ProjectionMatrix = getProjectionMatrix();     glm::mat4 ViewMatrix = getViewMatrix();     glm::mat4 ModelMatrix = glm::mat4(1.0);     glm::mat4 MVP = ProjectionMatrix * ViewMatrix * ModelMatrix;          // Send our transformation to the currently bound shader,      // in the "MVP" uniform     glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);          // Bind our texture in Texture Unit 0     glActiveTexture(GL_TEXTURE0);     glBindTexture(GL_TEXTURE_2D, Texture);     // Set our "myTextureSampler" sampler to user Texture Unit 0     glUniform1i(TextureID, 0);          // 1rst attribute buffer : vertices     glEnableVertexAttribArray(0);     glBindBuffer(GL_VERTEX_ARRAY, bsp.numOfFaces);     glVertexAttribPointer(     0,                  // attribute. No particular reason for 0, but must match the layout in the shader.     3,                  // size     GL_FLOAT,           // type     GL_FALSE,           // normalized?     0,                  // stride     (void*)0            // array buffer offset     );          // 2nd attribute buffer : UVs     glEnableVertexAttribArray(1);     glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);     glVertexAttribPointer(     1,                                // attribute. No particular reason for 1, but must match the layout in the shader.     2,                                // size : U+V => 2     GL_FLOAT,                         // type     GL_FALSE,                         // normalized?     0,                                // stride     (void*)0                          // array buffer offset     );          bsp.DrawBSP();          glDisableVertexAttribArray(0);     glDisableVertexAttribArray(1);          // Swap buffers     glfwSwapBuffers(window);     glfwPollEvents();          } // Check if the ESC key was pressed or the window was closed     while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS &&     glfwWindowShouldClose(window) == 0);          // Cleanup VBO and shader     glDeleteBuffers(1, &uvbuffer);     glDeleteProgram(programID);     glDeleteTextures(1, &TextureID);     glDeleteVertexArrays(1, &VertexArrayID);          // Close OpenGL window and terminate GLFW     glfwTerminate();          return 0;     }   Originally, the problem persisted within the file reading. Its fixed (I think), but its still not rendering the map correctly. Also, I tried GL_QUADS, GL_TRIANGLES, GL_TRIANGLE_STRIP, and GL_LINES in the glDrawElements function in the bsp header, all of them EXCEPT GL_QUADS generated the same looking result. GL_QUADS generated nothing. (I expected this as Q3 map specs stated it must be a triangle)   Thanks! All helps appreciated