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

Author Topic: Using sf::VertexArray to draw quads with multiple textures  (Read 2902 times)

0 Members and 1 Guest are viewing this topic.

andariel97

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
Using sf::VertexArray to draw quads with multiple textures
« on: November 29, 2016, 12:35:45 pm »
In modern opengl, in order to draw quads fast you create a vertexbuffer and you tell the gpu how your data is organised in those bites. The code looks something like this :
void setupMesh()
{
    glGenVertexArrays(1, &this->VAO);
    glGenBuffers(1, &this->VBO);
    glGenBuffers(1, &this->EBO);
 
    glBindVertexArray(this->VAO);
    glBindBuffer(GL_ARRAY_BUFFER, this->VBO);

    glBufferData(GL_ARRAY_BUFFER, this->vertices.size() * sizeof(Vertex),
                 &this->vertices[0], GL_STATIC_DRAW); 

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->EBO);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, this->indices.size() * sizeof(GLuint),
                 &this->indices[0], GL_STATIC_DRAW);

    // Vertex Positions
    glEnableVertexAttribArray(0);   
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex),
                         (GLvoid*)0);
    // Vertex Normals
    glEnableVertexAttribArray(1);   
    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex),
                         (GLvoid*)offsetof(Vertex, Normal));
    // Vertex Texture Coords
    glEnableVertexAttribArray(2);   
    glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex),
                         (GLvoid*)offsetof(Vertex, TexCoords));

    glBindVertexArray(0);


You also use texture units to tell the gpu where are your textures.
glBindTexture(GL_TEXTURE_2D, this->textures.id);

In sfml you can use sf::VertexArray to draw multiple sprites at once. But how do you tell sfml do draw those quads with diferent textures?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Using sf::VertexArray to draw quads with multiple textures
« Reply #1 on: November 29, 2016, 12:58:25 pm »
You can't, the SFML API is not made for that. There's only one set of texture coordinates and one active texture.
Laurent Gomila - SFML developer

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Using sf::VertexArray to draw quads with multiple textures
« Reply #2 on: November 29, 2016, 03:15:01 pm »
usually in 3D application, the texture and and light data are gathered with so called material for 3D models. you can write your own data-structure to represent it in your engine/game.

for me i made simple 3D engine to mimic SFML Graphics-package as much as i can, in my approach i have render components as SFML did like RenderWindow, RenderTarget... etc. and for models management i made Mesh, Material classes. the engine depends on programmable pipeline shaders as modern opengl attend to be.
here snippet how the different textures handled via RenderTarget and Materiel classes.






 

anything