Cześć! Aktualnie uczę się o ładowaniu tekstur w open gl z
I nie wiem na jakiej zasadzie działa void * pointer glVertexAttribPointer
Wiem, że ustawia ono miejsce od którego chcemy brać zmienne. Tylko nie wiem co wpisać kiedy zamiast struktur jak
struct ColorRGBA8
{
ColorRGBA8() : r(0), g(0), b(0), a(0) { }
ColorRGBA8(GLubyte R, GLubyte G, GLubyte B, GLubyte A) :
r(R), g(G), b(B), a(A) { }
GLubyte r;
GLubyte g;
GLubyte b;
GLubyte a;
};
struct UV
{
float u, v;
};
struct Position
{
float x;
float y;
};
class Vertex
{
public:
Vertex();
Position position;
ColorRGBA8 color;
UV uv;
void setUV(float u, float v);
void setPosition(float x, float y);
void setColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a);
};
będę miał jedną klasę
class Vertex{
public:
float x,y, u,v;
GLubyte r,g,b,a;
void setUV(float u, float v);
void setPosition(float x, float y);
void setColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a);
};
Oraz zastanawia mnie jeszcze czy naprawdę potrzeba nam aż 3 klas żeby ładować tekstury
enum class SortType
{
NONE, FRONT_TO_BACK, BACK_TO_FRONT, TEXTURE
};
class Glyph
{
public:
Glyph();
GLuint texture;
float w, h, depth;
Vertex topLeft;
Vertex topRight;
Vertex bottomLeft;
Vertex bottomRight;
private:
};
class RenderBatch
{
public:
RenderBatch(GLuint Offset, GLuint NumVertices, GLuint Texture);
~RenderBatch();
GLuint offset;
GLuint numVertices;
GLuint texture;
private:
};
class SpriteBatch
{
public:
SpriteBatch();
~SpriteBatch();
void Init();
void Begin(SortType sort = SortType::TEXTURE);
void End();
void Draw(glm::vec4 destRect, glm::vec4 uvRect, GLuint texture, ColorRGBA8 color);
void Render();
private:
void CreateRenderBatches();
void CreateVertex();
GLuint vbo;
GLuint vao;
void Sort();
static bool compereFrontToBack(Glyph *a, Glyph *b);
static bool compereBackToFront(Glyph *a, Glyph *b);
static bool compereTexture(Glyph *a, Glyph *b);
std::vector<Glyph*> glyph;
std::vector<RenderBatch> renderBatches;
SortType sortType;
};