Jump to content
  • Advertisement

Borax Kid

Member
  • Content Count

    24
  • Joined

  • Last visited

Community Reputation

221 Neutral

About Borax Kid

  • Rank
    Member
  1.  Oh that's nice! So does it work the same with Uniform Buffers ?   And thanks for answering
  2. Hi.   I'm experimenting with Vulkan and wanted to try and build a material system.   In this repo: https://github.com/SaschaWillems/Vulkan in the SceneRendering example, the developer uses push constants to pass the material properties to the shader. (https://github.com/SaschaWillems/Vulkan/blob/master/scenerendering/scenerendering.cpp line 532 at the time I write this)   I was wondering if instead of sending the same material properties every frame even if they didn't change, is it possible to send them to the shader only when they change?   I thought about that because maybe in the future I'll want to display thousands of different models with different materials and I'm not sure if the push constants will keep up.   I hope I'm being understandable.   Thanks!
  3. Hi.   I'm currently developping a Splatoon "demake" in top down view, using SFML for all the graphic part and Box2D for the physic part. I want the player to be able to "ink" or paint the floor, like in the real game. What would be a good way to implement this with SFML ? I have to be able to know quickly what color the player is standing on too.   Any advices on how to proceed ?   Thanks
  4. Borax Kid

    [Solved] Weird thing with VBO

    Thanks for answering   The thing is, the voxels are where they should be, there is no duplicates.     First of all: thanks, I'm very new to OpenGL and am doing this to learn this API with a concrete thing. Since a voxel has only one unique color on all its 6 faces (without lighting at least), I thought that could work the way I did it. I don't know how else could I manage to get to this result. I also thought about creating 2 3d array of vertices, one for their position (with the x, y, z) and another one with the same size but with colors of each vertices, but I wasn't sure on how to send this to the shader at the time.   So after I read you're comment, I tried and do it. It works properly, and I think it's better. The only problem is that I now use 2 3d array instead of 1 4d array, so some more memory is needed, but in the end, that's a better thing.   So thanks a lot for telling me the way I did it was shitty :) Now it works better.
  5. Hi   I'm currently developping a voxel world renderer (in C++), which is divided by chunks. A VBO is generated for each chunk, but there is some weird behavior with some colors.   A video will be easier to understand the problem : (sorry for potato quality, i don't know what settings should I render a 480p video).   This happens only with some colors, I don't know where does it come from.   I pass the color of the vertices with the position, in a 4D array, (x, y, z, color) like this : int color = ((red) << 16) | ((green) << 8) | (blue); vertices[i] = float4(x, y, z, color); glEnableVertexAttribArray(attributeCoord);    glBindBuffer(GL_ARRAY_BUFFER, vertices); glVertexAttribPointer(attributeCoord, 4, GL_INT, GL_FALSE, 0, 0);    glDrawArrays(GL_TRIANGLES, 0, i);    glDisableVertexAttribArray(attributeCoord); and in the fragment shader varying float f_color; void main(void) { int rgb; float red; float green; float blue; rgb = f_color; red = ((rgb >> 16) & 255) / 255.0; green = ((rgb >> 8) & 255) / 255.0; blue = (rgb & 255) / 255.0; gl_FragColor.rgb = vec3(red, green, blue); } Does anybody have any idea where this can be coming from ?   PS: The problem happens only with color with a blue component of zero
  6. Hi.   I'm developing a little 3d Voxel world engine to learn OpenGL and I came across a problem.   Nothing is drawn on the screen.   My code is structured like this : a class Renderer which is here to call the display function and keep useful things (the program for the shaders etc) and which contains a vector of Chunks. The Chunk class contain an array of 16*16*16 "blocks", stored in a glm::tvec4<GLbyte> where xyz is the position of the block (no need to have float or double, since every blocks are the same size) and w is an index for the color of the block.   Here is a sample of the code   main.cpp Renderer *g_window; /* all the onFunctions, which calls the Renderer::onFunction corresponding */ int main(int ac, char **av) { g_window = new Renderer; g_window->init(ac, av); g_window->createWindow(vector2i(500, 0), vector2i(1280, 720), "OpenGL"); if (g_window->resources()) { glutDisplayFunc(onDisplay); glutReshapeFunc(onReshape); glutIdleFunc(onIdle); glutSpecialFunc(onSpecial); glutSpecialUpFunc(onSpecialUp); glutIdleFunc(onDisplay); glutPassiveMotionFunc(onMotion); glutMotionFunc(onMotion); glutMainLoop(); } delete (g_window); return (0); } Renderer.cpp /* Constructor, destructor and other methods */ void Renderer::createWindow(vector2i winPos, vector2i winSize, const char *winTitle) { this->_winSize = winSize; glutInitWindowPosition(winPos.x, winPos.y); glutInitWindowSize(this->_winSize.x, this->_winSize.y); glutCreateWindow(winTitle); this->_chunks.push_back(new Chunk); this->_chunks.at(0)->createMesh(); if (glewInit() != GLEW_OK) { std::cerr << "glewInit failed" << std::endl; exit(1); } if (glewIsSupported("GL_VERSION_4_5")) std::cerr << "GLEW Version is 4.5" << std::endl; else std::cerr << "GLEW 4.5 not supported" << std::endl; } bool Renderer::resources() { this->_program = createProgram("cube.v.glsl", "cube.f.glsl"); if (this->_program == 0) return (false); this->_attribute_coord = glGetAttribLocation(this->_program, "coord"); if (this->_attribute_coord == -1) { std::cerr << "Could not bind attribute coord3d." << std::endl; return (false); } this->_uniform_mvp = glGetUniformLocation(this->_program, "mvp"); if (this->_uniform_mvp == -1) { std::cerr << "Could not bind attribute mvp." << std::endl; return (false); } glUseProgram(this->_program); glEnableVertexAttribArray(this->_attribute_coord); return (true); } void Renderer::beginScene() const { glm::mat4 view = glm::lookAt(this->_position, this->_position + this->_lookAt, glm::vec3(0, 1, 0)); glm::mat4 projection = glm::perspective(45.0f, 1.0f * this->_winSize.x / this->_winSize.y, 0.01f, 1000.0f); glm::mat4 mvp = projection * view; glUniformMatrix4fv(this->_uniform_mvp, 1, GL_FALSE, glm::value_ptr(mvp)); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } void Renderer::endScene() const { glutSwapBuffers(); } void Renderer::onDisplay() { this->beginScene(); this->renderChunks(); this->endScene(); } void Renderer::renderChunks() { int i; i = -1; while (++i < this->_chunks.size()) { this->_chunks.at(i)->render(this->_attribute_coord); } } /* And others method for mouse movement etc */ Chunk.cpp /* Constructor, destructor and other methods to create the chunks */ void Chunk::render(GLint attribute_coord) { if (!this->_currentVertex) return; glBindBuffer(GL_ARRAY_BUFFER, this->_vbo); glVertexAttribPointer(attribute_coord, 4, GL_BYTE, GL_FALSE, 0, 0); glDrawArrays(GL_TRIANGLES, 0, this->_currentVertex); } cube.v.glsl attribute vec4 coord; uniform mat4 mvp; varying vec4 color; void main(void) { color = coord; gl_Position = mvp * vec4(coord.xyz, 1); } cube.f.glsl varying vec4 color; void main(void) { if (color.w < 128) gl_FragColor = vec4(128.0, 128.0, 128.0, 1.0); else gl_FragColor = vec4(255.0, 255.0, 255.0, 1.0); } My thought is that I forgot an important OpenGL function maybe, but I've been looking at OpenGL tutorials and codes and I don't find my mistake.   I hope someone can find my mistake.   Thanks a lot   EDIT: added vertex and fragment shaders
  7. Borax Kid

    OpenGL How to add vertices in a VBO

    Thanks a lot everybody, so what I did is that i stock each triangle in a 4D vector (using glm::tvec4<GLbyte>) where the 4th dimension is used for the color of the triangle.   But I have a problem, not with this thing particularly, I think, but nothing is drawn on the screen.   Here's how my code is structured:   main.cpp int main(int ac, char **av) { g_window = new Renderer; g_window->init(ac, av); g_window->createWindow(vector2i(500, 0), vector2i(1280, 720), "OpenGL"); if (g_window->resources()) { glutDisplayFunc(onDisplay); glutReshapeFunc(onReshape); glutIdleFunc(onIdle); glutSpecialFunc(onSpecial); glutSpecialUpFunc(onSpecialUp); glutIdleFunc(onDisplay); glutPassiveMotionFunc(onMotion); glutMotionFunc(onMotion); glutMainLoop(); } delete (g_window); return (0); } Renderer.cpp /* Constructor, destructor and other methods */ void Renderer::createWindow(vector2i winPos, vector2i winSize, const char *winTitle) { this->_winSize = winSize; glutInitWindowPosition(winPos.x, winPos.y); glutInitWindowSize(this->_winSize.x, this->_winSize.y); glutCreateWindow(winTitle); this->_chunks.push_back(new Chunk); this->_chunks.at(0)->createMesh(); if (glewInit() != GLEW_OK) { std::cout << "glewInit failed" << std::endl; exit(1); } if (glewIsSupported("GL_VERSION_4_5")) std::cout << "GLEW Version is 4.5" << std::endl; else std::cout << "GLEW 4.5 not supported" << std::endl; } bool Renderer::resources() { this->_program = createProgram("cube.v.glsl", "cube.f.glsl"); if (this->_program == 0) return (false); this->_attribute_coord = glGetAttribLocation(this->_program, "coord"); if (this->_attribute_coord == -1) { std::cerr << "Could not bind attribute coord3d." << std::endl; return (false); } this->_uniform_mvp = glGetUniformLocation(this->_program, "mvp"); if (this->_uniform_mvp == -1) { std::cerr << "Could not bind attribute mvp." << std::endl; return (false); } glUseProgram(this->_program); glEnableVertexAttribArray(this->_attribute_coord); return (true); } void Renderer::beginScene() const { glm::mat4 view = glm::lookAt(this->_position, this->_position + this->_lookAt, glm::vec3(0, 1, 0)); glm::mat4 projection = glm::perspective(45.0f, 1.0f * this->_winSize.x / this->_winSize.y, 0.01f, 1000.0f); glm::mat4 mvp = projection * view; glUniformMatrix4fv(this->_uniform_mvp, 1, GL_FALSE, glm::value_ptr(mvp)); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } void Renderer::endScene() const { glutSwapBuffers(); } void Renderer::onDisplay() { this->beginScene(); this->renderChunks(); this->endScene(); } void Renderer::renderChunks() { int i; i = -1; while (++i < this->_chunks.size()) { this->_chunks.at(i)->render(this->_attribute_coord); } } /* And others method for mouse movement etc */ Chunk.cpp void Chunk::render(GLint attribute_coord) { if (!this->_currentVertex) return; glBindBuffer(GL_ARRAY_BUFFER, this->_vbo); glVertexAttribPointer(attribute_coord, 4, GL_BYTE, GL_FALSE, 0, 0); glDrawArrays(GL_TRIANGLES, 0, this->_currentVertex); } So Renderer is a class I made that contains everything needed for rendering, such as the program for the shaders etc.   I'm a begginer in OpenGL and I don't know where the problem is.   Thanks for helping me!   EDIT: Sorry if i wasn't clear in the first post, what i wanted wasn't a trick to resize a VBO but just to add vertices to it (just once, at the creation of it).
  8. Hi.   I'm making a voxel world renderer to learn OpenGL. I divided the world in Chunks (group of blocks/voxels) and I thought that the rendering could be optimized if only one draw call was done per chunk, instead of one draw call per block. The problem is that I don't know how to add vertices to the VBO, and I don't think it is possible. I'm learning OpenGL with this wikibook : http://en.wikibooks.org/wiki/OpenGL_Programming but it only shows how to use VBOs for a known number of vertices (a single cube for example). Is there a way to add vertices to a VBO ?   Or if that's not possible, is there a way to create a mesh and add triangles or vertices to it and then display it ?   I'm sorry if this question has already been asked, I couldn't find what I wanted to know.   Thanks a lot.
  9.   Is the map 'deformable'? (Can terrain cost be alter by player abilities or events?)   Didn't think about it. Let's say no
  10. Thanks for all the replies guys !   Set max movement points based on unit, with terrains using varied amounts depending on unit type (tread cost differs from tire cost when driving through woods, for example). Those are the Advance Wars rules.     I am familiar with this ruleset, but as the OP mentionned making something similar to, I was wondering if 'facing' and turns had to be considered as well. It's much easier to forego orientation, obviously.   'facing' and turns won't cost any 'points'. The movemen is limited by the terrain tiles (only this type of unit can go there etc) and by the presence of ennemy units. They can't superpose.     You're looking for a graph algorithm. Here's an article: http://en.wikipedia.org/wiki/Graph_%28abstract_data_type%29   The trick here is being able to treat your map like a graph without actually trying to build a graph in memory. You can figure out things like edges and costs from your map data on the fly, and implement any graph algorithm that way.   To find the spaces and the paths, I would start out with Dijkstra's algorithm: http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm   The wikipedia has a little animation of how the algorithm would act on a grid. I don't know if it really says anything about how to treat a typical 2D array as a graph. There are probably some concrete examples out there for 2D grids already.   I hope that's enough to get started.   I will look at it, thanks.
  11. Hello.   I'm making a turn based strategy game (heavily inspired by advance wars) and I want to implement a tiled movement like in advance wars : I can't figure out the algorithm to find the tiles where the unit can move, it also has to detect if there is an obstacle. So it seems to me the algorithm has to do 2 things, first find all the tiles where the unit can go, and second find the shortest path between the unit and the cursor.   What would be a good way to implement this type of algorithm ?   Thanks.
  12. Borax Kid

    [C++] How to implement a 16/9 map ?

      Yeah that's what I was thinking, didn't use the good term though.   Again, thanks for the answers, but I managed to do it myself, the correct algorithm was : (edit: atleast one correct algorithm) while (i < tile_x) { j = 0; while (j < tile_y) { if (j % 2 == 0) { tmp.x = i * tile_width; tmp.y = j * tile_height / 2; } else { tmp.x = i * tile_width + tile_width / 2; tmp.y = (j - 1) * tile_height / 2 + tile_height / 2; } sprite.setPosition(tmp); app.draw(sprite); ++j; } ++i; } No, no need for this, it'll be simpler to have all rows with the same width.   Thanks for all the precisions, this'll be really helpful!   Glad to hear it!   Yes, but for now it's just a personnal project! I sure hope I can make it playable or sellable or something like that but for now it's just for fun.   Yes, I'm on your side with this, I don't want to use something that already made all the work for me, what's the fun in programming if you don't program?   Again, thank you everyone, GameDev.net really is a great community!
  13. Borax Kid

    [C++] How to implement a 16/9 map ?

    Thanks for replying.   I think you misunderstood what I wanted to do, or I didn't say it correctly. What I want to get is this type of map :   But what I get is something like : (what I call a diamond shape) So with what I want, I can fill the entire screen, with the diamond shape, I'd have to make it larger then the windows and draw something that is out of the window (the camera will be fix, that's why I just want the necessary tiles, and no others out of the camera view). I hope someone will have an answer for this!
  14. Hello.   I made a little game some time ago (a 2d shooter, like a Worms game but in real time, for a school project), and now I want to make another game, but this time, isometric. I don't know where to begin with the isometric thing. The "problem" is that I have no idea how to make a 16/9 ratio isometric map, all the games and tuts about isometric I see use just a diamond shape, and not a rectangular one. How could I implement this in a simple way ? (Or complex way if there isn't any simple !)   PS: For my first game, I used the SFML graphics engine, and made pixel art sprites, but I want to try vectors graphics, do you know how can I do it with SFML ? Else which engine would you recommend me ?   Thanks for your time! Hope you can help me here.   (English isn't my native language, I'm sorry if I made some mistakes, I tried to write the best as possible.)
  15. Borax Kid

    How to program tile transitions (C++/SFML)

    Thanks a lot, everything (at least concerning tiles transitions and Y axis sorting) is done. I also made another topic for the sorting, if anyone is interested, it's here : http://www.gamedev.net/topic/660632-solved-sorting-a-stdmap/
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!