• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By Ty Typhoon
      I like to build my A - Team now.
       
      I need loyal people who can trust and believe in a dream.
      If you got time and no need for direct pay please contact me now.
       
      We cant pay now, you will recieve a lifetime percentage if the released game will give earnings. 
      If I get the best people together for a team, everything should be possible.
       
       
      What i need:
      - Programmer c++
      - Unity / Unreal - we must check whats possible, please share your experience with me.
      - Sculpter, 3D Artist
      - Animator
      - Marketing / Promotion 
       
       
      What i do:
      - Studio Owner
      - Director
      - Recruit exactly you
      - Sounddesign
      - Main theme composing
      - Vocals
      - Game design
      - Gun, swords, shields and weapon design
      - Character, plants and animal design
       
       
      Please dont ask about the Name of the Game, about Designs or Screenshots.
      The game will be defintitly affected about our and your skills if you join the team.
       
       
      Planned for the big Game:
      - 1st person shooter
      - online multiplayer
      - character manipulation
      - complete big open world with like lifetime actions and reactions
      - gunstore with many items to buy
      - many upgrades for players
      - specials like mini games
       
      So if you are interested in joining a team with a nearly complete game idea, contact me now and tell me what you can do.
       
      discord:
      joerg federmann composing#2898
       
       
    • By codelyoko373
      I wasn't sure if this would be the right place for a topic like this so sorry if it isn't.
      I'm currently working on a project for Uni using FreeGLUT to make a simple solar system simulation. I've got to the point where I've implemented all the planets and have used a Scene Graph to link them all together. The issue I'm having with now though is basically the planets and moons orbit correctly at their own orbit speeds.
      I'm not really experienced with using matrices for stuff like this so It's likely why I can't figure out how exactly to get it working. This is where I'm applying the transformation matrices, as well as pushing and popping them. This is within the Render function that every planet including the sun and moons will have and run.
      if (tag != "Sun") { glRotatef(orbitAngle, orbitRotation.X, orbitRotation.Y, orbitRotation.Z); } glPushMatrix(); glTranslatef(position.X, position.Y, position.Z); glRotatef(rotationAngle, rotation.X, rotation.Y, rotation.Z); glScalef(scale.X, scale.Y, scale.Z); glDrawElements(GL_TRIANGLES, mesh->indiceCount, GL_UNSIGNED_SHORT, mesh->indices); if (tag != "Sun") { glPopMatrix(); } The "If(tag != "Sun")" parts are my attempts are getting the planets to orbit correctly though it likely isn't the way I'm meant to be doing it. So I was wondering if someone would be able to help me? As I really don't have an idea on what I would do to get it working. Using the if statement is truthfully the closest I've got to it working but there are still weird effects like the planets orbiting faster then they should depending on the number of planets actually be updated/rendered.
    • By BenjaminBouchet
      Learning game development in Unreal Engine could be a daunting task for someone who don’t know where to start, and a cumbersome process if you don’t organize your progression correctly. One thing commonly known by experienced developers and by people unfamiliar with coding: mastering a development language is a long and difficult task.
      From blueprints to C++ in Unreal Engine
      If you want to learn fast, you need a good learning strategy. Unreal Engine contains a very powerful tool which you can use to learn C++ faster: its blueprint system. Blueprints are extremely easy to learn (and you may already have a good knowledge of them). Thus you can conveniently use them as a guide for writing code in C++. This is the reason why I am writing a tutorial series on how to make the transition from Unreal Engine blueprints to C++.
      Learn and practice C++
      Following this tutorial, you’ll acquire new concepts of C++ programming in every chapter. Then following chapters will give you reasons to reuse and practice those same concepts. There’s no better way to wire you brain.
      Link to the tutorial: [Tutorial] Learn C++ in Unreal Engine 4 by making a powerful camera
      Please do send me as much feedback as you want. I’ll be considering every constructive remarks and taking them into consideration. Your feedback will help me to improve and update the existing chapters and to make the next one better.

      View full story
    • By BenjaminBouchet
      Learning game development in Unreal Engine could be a daunting task for someone who don’t know where to start, and a cumbersome process if you don’t organize your progression correctly. One thing commonly known by experienced developers and by people unfamiliar with coding: mastering a development language is a long and difficult task.
      From blueprints to C++ in Unreal Engine
      If you want to learn fast, you need a good learning strategy. Unreal Engine contains a very powerful tool which you can use to learn C++ faster: its blueprint system. Blueprints are extremely easy to learn (and you may already have a good knowledge of them). Thus you can conveniently use them as a guide for writing code in C++. This is the reason why I am writing a tutorial series on how to make the transition from Unreal Engine blueprints to C++.
      Learn and practice C++
      Following this tutorial, you’ll acquire new concepts of C++ programming in every chapter. Then following chapters will give you reasons to reuse and practice those same concepts. There’s no better way to wire you brain.
      Link to the tutorial: [Tutorial] Learn C++ in Unreal Engine 4 by making a powerful camera
      Please do send me as much feedback as you want. I’ll be considering every constructive remarks and taking them into consideration. Your feedback will help me to improve and update the existing chapters and to make the next one better.
    • By mrDIMAS
      Hello everyone! I need to fill lua table with functions from script file like this:
      function init() end function update() end I need to create table on stack and fill it with this functions from specified file. How can I do this?
  • Advertisement
  • Advertisement

Merging multiple meshes into one

Recommended Posts

I'm currently working on a Minecraft-like game ( a world made of blocks ).

Until now it seems to be working very fine. But I can feel that the more blocks I'm adding to one world the slowlier it runs ( CPU throttles it ).

My solution would be to put the vertex/index data of all same blocks ( same texture etc. ) into one one vertex/index buffer to relieve the CPU since I wont need that much draw calls anymore.

Have you got any ideas of how I could do this the best way?

Share this post


Link to post
Share on other sites
Advertisement

Make a larger buffer, fill it, and send it to the GPU?

Likely you can also add a field what texture to draw etc, and pass that data to the fragment shader.

 

However, did you actually check that drawing is the problem? Lots of things take more time when you make your world larger / more complex.

By profiling the code, you get information where the real problem actually is, rather than random guessing and changing areas that you believe to take time (which in my experience is consistently wrong, or at least, I haven't yet been able to guess correctly).

Share this post


Link to post
Share on other sites

Right now I'm calling the render function for every cube. I'll try to create a function that puts all the single cubes into one big buffer. Thats exactly what my first idea was.

Iterating through the list of cubes takes the most time I guess ( don't have a profiler but I commentend out different parts of the code ).

Share this post


Link to post
Share on other sites

So I played around a little bit. This is what I'm doing:

void Mesh::AddMesh( Mesh& other, glm::vec3 translation )
{
    std::cout << "I'm adding meshes." << std::endl;

    if ( ( other.vecVertices.size(  ) % 5 != 0 ) && ( other.vecIndices.size(  ) % 3 != 0 ) )
    {
        std::cout << "The mesh you wanted to add didn't contain good data. Canceling addition." << std::endl;
        return;
    }
    for ( unsigned int i = 0; i < other.vecVertices.size(  ) / 5; ++i )
    {
        // Add translated position coords
        vecVertices.push_back( other.vecVertices[i * 5] + translation.x );
        vecVertices.push_back( other.vecVertices[i * 5 + 1] + translation.y );
        vecVertices.push_back( other.vecVertices[i * 5 + 2] + translation.z );
        // Add same texture coords
        vecVertices.push_back( other.vecVertices[i * 5 + 3] );
        vecVertices.push_back( other.vecVertices[i * 5 + 4] );
        
        // Demo Output
        std::cout << other.vecVertices[i * 5] + translation.x << ",\t";
        std::cout << other.vecVertices[i * 5 + 1] + translation.y << ",\t";
        std::cout << other.vecVertices[i * 5 + 2] + translation.z << ",\t";
        std::cout << other.vecVertices[i * 5 + 3] << ",\t";
        std::cout << other.vecVertices[i * 5 + 4] << std::endl;


        /*std::cout << vecVertices << ",\t";
        std::cout << vecVertices[i + 1] << ",\t";
        std::cout << vecVertices[i + 2] << ",\t";
        std::cout << vecVertices[i + 3] << ",\t";
        std::cout << vecVertices[i + 4] << std::endl;*/
    }
    for ( unsigned int i = 0; i < other.vecIndices.size(  ); ++i )
    {
        //std::cout << other.vecIndices + ( vecVertices.size(  ) / 5 ) << std::endl;
        vecIndices.push_back( other.vecIndices[i] + vecVertices.size(  ) - 1 );
    }

    UpdateBuffers(  );
}

It's a method for adding the vertex index data from one mesh to another. The vertices get translated by the given vec3 so the 2 objects aren't just inside of each other. At the end the vao/vbo/ibo get recreated.

I checked the output in the console and it looked correct to me. But there still is only showing up one cube after adding another one to it.

void Mesh::UpdateBuffers(  )
{
    // Deleting old stuff
    glDeleteVertexArrays( 1, &m_VAO );
    glDeleteBuffers( 1, &m_VBO );
    glDeleteBuffers( 1, &m_IBO );

    // Generating new buffers
    glGenVertexArrays( 1, &m_VAO );
    glGenBuffers( 1, &m_VBO );
    glGenBuffers( 1, &m_IBO );

    glBindVertexArray( m_VAO );
    glBindBuffer( GL_ARRAY_BUFFER, m_VBO );
    glBufferData( GL_ARRAY_BUFFER, vecVertices.size(  ) * sizeof( GLfloat ), &vecVertices[0], GL_STATIC_DRAW );

    glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_IBO );
    glBufferData( GL_ELEMENT_ARRAY_BUFFER, vecIndices.size(  ) * sizeof( GLushort ), &vecIndices[0], GL_STATIC_DRAW );

    // Position Attribute
    glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof( GLfloat ), (void*) 0 );
    glEnableVertexAttribArray( 0 );

    // texture coord attribute
    glVertexAttribPointer( 1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof( GLfloat ), (void*)(3 * sizeof(float)));
    glEnableVertexAttribArray( 1 );

    glBindBuffer( GL_ARRAY_BUFFER, 0 );

    glBindVertexArray( 0 );



    std::cout << "Vertex count: " << vecVertices.size(  ) / 5 << std::endl;
    std::cout << "Index count: " << vecIndices.size(  ) << std::endl;
}
void Mesh::Render(  )
{
    glBindVertexArray( m_VAO );
    //std::cout << "Num Vertices/Indices: " << vecVertices.size(  ) << "/" << vecIndices.size(  ) << std::endl;
    glDrawElements( GL_TRIANGLES, vecIndices.size(  ), GL_UNSIGNED_SHORT, 0 );
}

When rendering it says that I have 72 ( 36 * 2 for 2 cubes ) indices and 2 times the amount of vertices of the single cube.

Are the positions of vertices allowed to exceed 1 btw? Does openGL accept vertex positions like vec3( 0.0f, 1.5f, 2.0f )?

Edited by nullhandle

Share this post


Link to post
Share on other sites

I don't know about the OpenGL code, someone else should answer that.

 

58 minutes ago, nullhandle said:

Are the positions of vertices allowed to exceed 1 btw? Does openGL accept vertex positions like vec3( 0.0f, 1.5f, 2.0f )?

Sure, you can store anything that  fits in a float. The only thing you need to consider is that OpenGL draws things between -1 and +1, so you need a position transformation in the vertex shader to move the right part in sight of the camera.

Share this post


Link to post
Share on other sites

I found the problem..... should buy a rubber duck soon. I wasn't correctly adding the indices of the mesh I wanted to add. For people wondering, this is the working function:

void Mesh::AddMesh( Mesh& other, glm::vec3 translation )
{
    std::cout << "I'm adding meshes." << std::endl;

    if ( ( other.vecVertices.size(  ) % 5 != 0 ) && ( other.vecIndices.size(  ) % 3 != 0 ) )
    {
        std::cout << "The mesh you wanted to add didn't contain good data. Canceling addition." << std::endl;
        return;
    }
    size_t oldVecVerticesSize = vecVertices.size(  );
    for ( unsigned int i = 0; i < other.vecVertices.size(  ) / 5; ++i )
    {
        // Add translated position coords
        vecVertices.push_back( other.vecVertices[i * 5] + translation.x );
        vecVertices.push_back( other.vecVertices[i * 5 + 1] + translation.y );
        vecVertices.push_back( other.vecVertices[i * 5 + 2] + translation.z );
        // Add same texture coords
        vecVertices.push_back( other.vecVertices[i * 5 + 3] );
        vecVertices.push_back( other.vecVertices[i * 5 + 4] );
    }
    for ( unsigned int i = 0; i < other.vecIndices.size(  ); ++i )
    {
        std::cout << other.vecIndices[i] + ( vecVertices.size(  ) / 5 ) << std::endl;
        vecIndices.push_back( other.vecIndices[i] + ( oldVecVerticesSize / 5 ) );
    }

    UpdateBuffers(  );
}

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Advertisement