Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: BlackScreen when try to load VAO and VBO on OpenGL 4.3  (Read 2739 times)

0 Members and 1 Guest are viewing this topic.

SoyElHomerMalo

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
BlackScreen when try to load VAO and VBO on OpenGL 4.3
« on: August 01, 2014, 08:28:41 pm »
Hi!

I was looking for my problem but I haven't found the solution.

So the problem is...I have the main menu of my game created and working with sfml 2.1. I have an OpenGL4.3 program working with GLFW3. Now, I want to write that program into my SFML project, but when I write the function LoadPlane(), that has the vertex_buffer and setup the VBO and VAO, and execute the project, the main menu disappears. I know the main menu is still working because I hear the music and the sounds and I can choose any option of the menu with de arrow keys, but I can't see anything, only a black screen.

Here is some code:

void LoadPlane() {
        // make and bind the VAO
        glGenVertexArrays(1, &gVAO);
        glBindVertexArray(gVAO);

        // Make a plane with triangles (two triangles per side)
        GLfloat vertex_positions[] =
        {
                // (X, Y), (U, V)
                -0.5f, -0.5f, 0.0f, 0.0f,
                -0.5f,  0.5f, 0.0f, 1.0f,
                 0.5f, -0.5f, 1.0f, 0.0f,
                 0.5f,  0.5f, 1.0f, 1.0f
        };

        // make and bind the VBO
        glGenBuffers(1, &gVBO);
        glBindBuffer(GL_ARRAY_BUFFER, gVBO);
        glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_positions), vertex_positions, GL_STATIC_DRAW);
        glEnableVertexAttribArray(0);
        glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), NULL);
        glEnableVertexAttribArray(1);
        glVertexAttribPointer(1, 2, GL_FLOAT, GL_TRUE, 4 * sizeof(GLfloat), (const GLvoid*)(2 * sizeof(GLfloat)));
}

        // init glew
                glewExperimental = true;
                if (glewInit() != GLEW_OK)
                        throw runtime_error("glewInit failed");

                // GLEW throws some errors, so discard all the errors so far
                while (glGetError() != GL_NO_ERROR) {}

                // make sure OpenGL version 4.3 API is available
                if (!GLEW_VERSION_4_3)
                        throw runtime_error("OpenGL 4.3 API is not available.");

                // OpenGL settings
                program = 0;
                glEnable(GL_DEPTH_TEST);
                glDepthFunc(GL_LESS);

                // Create the program and attach all the shaders
                LoadProgram();

                // create buffer and fill it with the points of the triangle
                LoadPlane();

                // load texture
                LoadTexture();

                // setup tessellation
                glPatchParameteri(GL_PATCH_VERTICES, 4);

                // setup model-view-projection matrix
                projectM = perspective((float)PI / 3, ((float) window.getSize().x / window.getSize().y), 0.1f, 100.0f);
                viewM = lookAt(pos, target, vec3(0, 1, 0));
                modelM = mat4();
                window.pushGLStates();

        // main loop with render and update

            #pragma region OpenGL Render
            win.popGLStates();
                        // use the progam
                        glUseProgram(program);

                        // calculate the mvp matrix and set the "mvp" uniform
                        glUniformMatrix4fv(glGetUniformLocation(program, "mvp"), 1, GL_FALSE, value_ptr(projectM * viewM * modelM));

                        // draw the VAO
                        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
                        glDrawArrays(GL_PATCHES, 0, 4);

                        win.pushGLStates();

                        // print GUI with sfml

If I comment LoadPlane(), I can see all the main menu.

Can someone help me?
« Last Edit: August 01, 2014, 08:39:32 pm by SoyElHomerMalo »

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

SoyElHomerMalo

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: BlackScreen when try to load VAO and VBO on OpenGL 4.3
« Reply #2 on: August 01, 2014, 08:59:01 pm »
Quote
http://en.sfml-dev.org/forums/index.php?topic=15820.0

Sorry binary1248, I read that post but I though it wasn't the same problem....and I didn't read your posts.

Thank you, unbind all buffers was the key.

 

anything