Skip to main content
Commonmark migration
Source Link

I have been learning opengl and I have made good progress over past few months. However I still struggle to understand game logic in C++, I am new to C++ too.

Say I have this program.

#include <headers>

int main()
{
    #Step 1
    VAO_VBO_EBO_inits();

    while(!glfwWindowShouldClose(window))
    {
        glClearColor(.2f, .2f, .3f, 1.f);
        glClear(GL_COLOR_BUFFER_BIT);

        #Step 2
        DrawCalss();

        glfwPollEvents();
        glfwSwapBuffers(window);
    };
    return 0;
};

For OpenGL programmers this should be clear. With this structure, I have to load all levels and then draw part of them like so.

#Step 1 feeds the gpu the vertex data and its attributes.

Step 1 feeds the gpu the vertex data and its attributes.

#Step 2 binds shader programs and draws the vertices

Step 2 binds shader programs and draws the vertices

Say I have A, B, C, D levels, within VAO_VBO_EBO_inits(); function I have to load all A, B, C, D levels then within DrawCalss(); function will draw only related levels.

DrawCalss(); function is dynamic but VAO_VBO_EBO_inits(); invoked only once.

What I want to do is create separate game loops for each levels and be able to switch between levels, and as I switch levels preceding level should be unloaded and next level reloaded.

Since I am new to C++ I don't know what way would be the most efficient, that's why I have not tried anything. How do I achieve it? what is the best practice for such scenarios?

I have been learning opengl and I have made good progress over past few months. However I still struggle to understand game logic in C++, I am new to C++ too.

Say I have this program.

#include <headers>

int main()
{
    #Step 1
    VAO_VBO_EBO_inits();

    while(!glfwWindowShouldClose(window))
    {
        glClearColor(.2f, .2f, .3f, 1.f);
        glClear(GL_COLOR_BUFFER_BIT);

        #Step 2
        DrawCalss();

        glfwPollEvents();
        glfwSwapBuffers(window);
    };
    return 0;
};

For OpenGL programmers this should be clear. With this structure, I have to load all levels and then draw part of them like so.

#Step 1 feeds the gpu the vertex data and its attributes.

#Step 2 binds shader programs and draws the vertices

Say I have A, B, C, D levels, within VAO_VBO_EBO_inits(); function I have to load all A, B, C, D levels then within DrawCalss(); function will draw only related levels.

DrawCalss(); function is dynamic but VAO_VBO_EBO_inits(); invoked only once.

What I want to do is create separate game loops for each levels and be able to switch between levels, and as I switch levels preceding level should be unloaded and next level reloaded.

Since I am new to C++ I don't know what way would be the most efficient, that's why I have not tried anything. How do I achieve it? what is the best practice for such scenarios?

I have been learning opengl and I have made good progress over past few months. However I still struggle to understand game logic in C++, I am new to C++ too.

Say I have this program.

#include <headers>

int main()
{
    #Step 1
    VAO_VBO_EBO_inits();

    while(!glfwWindowShouldClose(window))
    {
        glClearColor(.2f, .2f, .3f, 1.f);
        glClear(GL_COLOR_BUFFER_BIT);

        #Step 2
        DrawCalss();

        glfwPollEvents();
        glfwSwapBuffers(window);
    };
    return 0;
};

For OpenGL programmers this should be clear. With this structure, I have to load all levels and then draw part of them like so.

Step 1 feeds the gpu the vertex data and its attributes.

Step 2 binds shader programs and draws the vertices

Say I have A, B, C, D levels, within VAO_VBO_EBO_inits(); function I have to load all A, B, C, D levels then within DrawCalss(); function will draw only related levels.

DrawCalss(); function is dynamic but VAO_VBO_EBO_inits(); invoked only once.

What I want to do is create separate game loops for each levels and be able to switch between levels, and as I switch levels preceding level should be unloaded and next level reloaded.

Since I am new to C++ I don't know what way would be the most efficient, that's why I have not tried anything. How do I achieve it? what is the best practice for such scenarios?

Source Link
user133668
user133668

How do I initialise levels sequentially?

I have been learning opengl and I have made good progress over past few months. However I still struggle to understand game logic in C++, I am new to C++ too.

Say I have this program.

#include <headers>

int main()
{
    #Step 1
    VAO_VBO_EBO_inits();

    while(!glfwWindowShouldClose(window))
    {
        glClearColor(.2f, .2f, .3f, 1.f);
        glClear(GL_COLOR_BUFFER_BIT);

        #Step 2
        DrawCalss();

        glfwPollEvents();
        glfwSwapBuffers(window);
    };
    return 0;
};

For OpenGL programmers this should be clear. With this structure, I have to load all levels and then draw part of them like so.

#Step 1 feeds the gpu the vertex data and its attributes.

#Step 2 binds shader programs and draws the vertices

Say I have A, B, C, D levels, within VAO_VBO_EBO_inits(); function I have to load all A, B, C, D levels then within DrawCalss(); function will draw only related levels.

DrawCalss(); function is dynamic but VAO_VBO_EBO_inits(); invoked only once.

What I want to do is create separate game loops for each levels and be able to switch between levels, and as I switch levels preceding level should be unloaded and next level reloaded.

Since I am new to C++ I don't know what way would be the most efficient, that's why I have not tried anything. How do I achieve it? what is the best practice for such scenarios?