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

Author Topic: Having some issues displaying traingle with openGL  (Read 2835 times)

0 Members and 2 Guests are viewing this topic.

bryce910

  • Newbie
  • *
  • Posts: 31
    • View Profile
Having some issues displaying traingle with openGL
« on: November 21, 2015, 10:18:35 pm »
Okay so I have been working on this for hours and I simply can not understand what I am doing wrong. All I am trying to do is generate a Triangle in my sfml application and  yes I am failing miserably. Can someone explain to me what I am doing wrong?
Code: [Select]
GLenum err = glewInit();
if (err != GLEW_OK)
{
std::cout << "NOT WORKING" << std::endl;
}
GLuint vertextBuffer;
GLuint vertexArrayID;
glGenVertexArrays(1, &vertexArrayID);
glBindVertexArray(vertexArrayID);

glGenBuffers(1, &vertextBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertextBuffer);

g_vertex_buffer_data.push_back({ -1.0f, -1.0f, 0.0f });
g_vertex_buffer_data.push_back({1.0f, -1.0f, 0.0f});
g_vertex_buffer_data.push_back({ 0.0f, 1.0f, 0.0f });

glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), &g_vertex_buffer_data, GL_STATIC_DRAW);
        glDrawArrays(GL_TRIANGLES, 0, 3);
gameWindow.pushGLStates();
gameWindow.popGLStates();

I am not able to get anything to show up even for a simple triangle.

This is all the opengl code I  use including the draw functions

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: Having some issues displaying traingle with openGL
« Reply #1 on: November 21, 2015, 10:46:46 pm »
Are you mixing gl with the graphics module? If so check the order in which you push / pop sfml's gl state
http://www.sfml-dev.org/tutorials/2.3/window-opengl.php#using-opengl-together-with-the-graphics-module

bryce910

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Having some issues displaying traingle with openGL
« Reply #2 on: November 21, 2015, 10:52:30 pm »
I have those in the code by the openGL draw sequence:

Code: [Select]
        glDrawArrays(GL_TRIANGLES, 0, 3);
gameWindow.pushGLStates();
gameWindow.popGLStates();
       //back to sfml graphics modale drawing

If I use

Code: [Select]

static const GLfloat g_vertex_buffer_data1[] = {
- 1.0f, -1.0f, 0.0f,
    1.0f, -1.0f, 0.0f,
    0.0f, 1.0f, 0.0f,
};

instead of

Code: [Select]

std::vector<sf::Vector3f> g_vertex_buffer_data;


Then the triangle does draw? Are you not able to use vector3f for verticies?
« Last Edit: November 21, 2015, 11:09:34 pm by bryce910 »

bryce910

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Having some issues displaying traingle with openGL
« Reply #3 on: November 21, 2015, 11:23:10 pm »
Okay so I got it rendering now but all of the graphics modules I draw are flickering constantly behind the OpenGl object rendered

Code: [Select]
game.gameWindow.pushGLStates();
game.render(*background);
game.render(*object2);
game.render(*playMenu);
game.render(*quitMenu);
game.gameWindow.popGLStates();
glClear(GL_DEPTH_BUFFER_BIT);

glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertextBuffer);
glVertexAttribPointer(
0,
3,
GL_FLOAT,
GL_TRUE,
0,
(void *)0
);

glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
game.gameWindow.pushGLStates();
game.gameWindow.popGLStates();
                        game.gameWindow.display();

« Last Edit: November 21, 2015, 11:39:26 pm by bryce910 »

bryce910

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Having some issues displaying traingle with openGL
« Reply #4 on: November 22, 2015, 07:12:22 pm »
Hey guys!

After many long hours of working through this I ended up hiring someone to help me fix the problem. Apparently the issue was with my shader::Bind(&shader). Once I switched over to the opengl method of shading the triangle worked and the flickering stopped.