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

Author Topic: Drawing 3D Geometry (Vertex Arrays/VBOs)  (Read 4907 times)

0 Members and 1 Guest are viewing this topic.

PixelMuffin

  • Newbie
  • *
  • Posts: 18
    • View Profile
Drawing 3D Geometry (Vertex Arrays/VBOs)
« on: July 19, 2012, 05:39:09 am »
Hi.

I am trying to figure out where SFML takes care of things and where it lets OpenGL do its own thing when it comes to 3D rendering. I guess I am curious as to the capabilities of using shaders I have written that render 3D geometry in SFML.

Does anyone have a code example of rendering geometry from arrays? Even a simple example will do the trick (like a single triangle). I guess my confusion stems from the fact I have only used shaders on sprites and images in SFML but not geometry.

Thank you. Sorry if my question is confusing. If anyone has some simple code in which shaders are used to render 3D geometry from arrays, that would help me greatly.

PixelMuffin

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
Re: Drawing 3D Geometry (Vertex Arrays/VBOs)
« Reply #1 on: July 19, 2012, 09:40:13 am »
There's an OpenGL example that comes with the SDK, it should show you how you can use OpenGL with SFML. Afaik you can't use the sf::Shader class with your own 3D rendering, at least it's not really inteded.
SFML is a library for 2D graphics and other media stuff.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

PixelMuffin

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Drawing 3D Geometry (Vertex Arrays/VBOs)
« Reply #2 on: July 19, 2012, 11:09:02 am »
There's an OpenGL example that comes with the SDK, it should show you how you can use OpenGL with SFML. Afaik you can't use the sf::Shader class with your own 3D rendering, at least it's not really inteded.
SFML is a library for 2D graphics and other media stuff.

Thank you. That's what I was wondering. I figure I will implement my own shader loader and just do it the normal way. Thank you. But I can still use SFML on the rendered image once it's done, correct maybe to handle antialiasing or other stuff.

Thank you!

cooldog99

  • Jr. Member
  • **
  • Posts: 95
    • View Profile
    • Perilous Game Studios
Re: Drawing 3D Geometry (Vertex Arrays/VBOs)
« Reply #3 on: July 19, 2012, 02:31:59 pm »
I've been using sf::Shaders with my program without any issue, and as I remember SFML shaders are just GLSL shaders, with easier implementation.

basic VBO example:

::Header::
typedef struct{
    float x,y,z
}Vertex;

Vertex * Vertices;
GLuint myVBOID;
 

Init

Vertices = new Vertex[3]; // Size of 1 triangle
//basic triangle

Vertices[0].x = 0.f;
Vertices[0].y = 0.f;
Vertices[0].z = 0.f;

Vertices[1].x = 1.f;
Vertices[1].y = 0.f;
Vertices[1].z = 0.f;

Vertices[2].x = 1.f;
Vertices[2].y = 1.f;
Vertices[2].z = 0.f;

glGenBuffers(1, &myVBOID);
glBindBuffer(myVBOID);
glBufferData(GL_ARRAY_BUFFER, 3 * 3 * sizeof(float), Vertices, GL_STATIC_DRAW);
delete [] Vertices;
 

Drawing
glBindBuffer(myVBOID);
     glEnableClientState(GL_VERTEX_ARRAY);
     glVertexPointer(3, GL_FLOAT, 0, (char *) NULL);
     glDrawArrays(GL_TRIANGLES, 0, 3);
     glDisableClientState(GL_VERTEX_ARRAY);
 

Disposing
        if (Vertices != NULL)
                delete[] Vertices;
glDeleteBuffers(1, &myVBOID);
 

That's a basic triangle using VBO's

G.

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
Re: Drawing 3D Geometry (Vertex Arrays/VBOs)
« Reply #4 on: July 19, 2012, 09:16:18 pm »
Yeah but if you don't want to (or can't) use deprecated / removed functions like glVertexPointer or need more vertex attributes, you won't be able to use sf::Shader::setParameter and will have to write your own functions.
The point of using sf::Shader would be only as a shader loader / compiler, am I wrong ?

PixelMuffin

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Drawing 3D Geometry (Vertex Arrays/VBOs)
« Reply #5 on: July 19, 2012, 11:05:10 pm »
cooldog99, what if you wanted to use a shader in rendering that VBO? I don't see where the shader comes in to play? Are you using a fixed function pipeline?