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

Author Topic: Using Graphics module with OpenGL  (Read 1341 times)

0 Members and 1 Guest are viewing this topic.

Minastir

  • Newbie
  • *
  • Posts: 2
    • View Profile
Using Graphics module with OpenGL
« on: August 22, 2017, 11:43:26 pm »
Hello, I've used SFML in the past for 2d projects and decided to use it with OpenGL to learn 3d programming as well.
My goal is to make a program that renders a simple scene in overhead 2d, simple 3d projection using the SFML 2d graphics module and "real" 3d with OpenGL.
I started following the tutorial on http://www.opengl-tutorial.org/ but I immediately ran into problems.
I dug around on different forums for solutions and while adding
Code: [Select]
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
In the code after popGLStates() stopped my program from crashing, I still can't draw anything with the graphics module if I initialize drawing in OpenGL.
I isolated the problem into this piece of code.
Code: [Select]
GLfloat g_vertex_buffer_data[] = { -1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
0.0f, 1.0f, 0.0f, };
glGenBuffers(1, &vertexbuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);
If I run this, which apparently generates a VBO, puts some data into it and binds it for use, the graphics module stops doing anything, even if I use pushGLStates().
I'm sorry if this question is silly, but I'm a beginner with using OpenGL and I will appreciate any help you can give me.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Using Graphics module with OpenGL
« Reply #1 on: August 23, 2017, 09:28:13 am »
Don't try random things, the solution is simpler ;)

If binding a GL_ARRAY_BUFFER VBO breaks SFML rendering, then unbind it before drawing SFML stuff -- SFML doesn't manage those OpenGL states.
Laurent Gomila - SFML developer

Minastir

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Using Graphics module with OpenGL
« Reply #2 on: August 23, 2017, 10:02:07 pm »
Ok thank you.
This fixed the problem.
I don't even need to do glDisableClientState anymore.
I guess now I just have to be careful to restore all states I change after drawing with OpenGL.

 

anything