Redesign shader system and more
Shader system has been completely redesigned Added support for multiple texture color modes
This commit is contained in:
parent
ee4b553c2a
commit
c062f8d4fe
6 changed files with 247 additions and 196 deletions
|
@ -1347,6 +1347,7 @@ static void InitGraphics(void)
|
||||||
windowReady = true; // IMPORTANT!
|
windowReady = true; // IMPORTANT!
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
||||||
// GLFW3 Error Callback, runs on GLFW3 error
|
// GLFW3 Error Callback, runs on GLFW3 error
|
||||||
static void ErrorCallback(int error, const char *description)
|
static void ErrorCallback(int error, const char *description)
|
||||||
|
|
|
@ -1202,14 +1202,14 @@ void UnloadModel(Model model)
|
||||||
rlDeleteBuffers(model.vboId[2]);
|
rlDeleteBuffers(model.vboId[2]);
|
||||||
|
|
||||||
rlDeleteVertexArrays(model.vaoId);
|
rlDeleteVertexArrays(model.vaoId);
|
||||||
rlDeleteTextures(model.textureId);
|
rlDeleteTextures(model.texture.id);
|
||||||
rlDeleteShader(model.shaderId);
|
rlDeleteShader(model.shader.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetModelTexture(Model *model, Texture2D texture)
|
void SetModelTexture(Model *model, Texture2D texture)
|
||||||
{
|
{
|
||||||
if (texture.id <= 0) model->textureId = whiteTexture; // Default white texture (use mesh color)
|
if (texture.id <= 0) model->texture.id = whiteTexture; // Default white texture (use mesh color)
|
||||||
else model->textureId = texture.id;
|
else model->texture = texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw a model (with texture if set)
|
// Draw a model (with texture if set)
|
||||||
|
|
36
src/raylib.h
36
src/raylib.h
|
@ -266,22 +266,34 @@ typedef struct VertexData {
|
||||||
unsigned char *colors; // 4 components per vertex
|
unsigned char *colors; // 4 components per vertex
|
||||||
} VertexData;
|
} VertexData;
|
||||||
|
|
||||||
|
// Shader type
|
||||||
|
typedef struct Shader {
|
||||||
|
unsigned int id; // Shader program id
|
||||||
|
|
||||||
|
// Variable attributes
|
||||||
|
unsigned int vertexLoc; // Vertex attribute location point (vertex shader)
|
||||||
|
unsigned int texcoordLoc; // Texcoord attribute location point (vertex shader)
|
||||||
|
unsigned int normalLoc; // Normal attribute location point (vertex shader)
|
||||||
|
unsigned int colorLoc; // Color attibute location point (vertex shader)
|
||||||
|
|
||||||
|
// Uniforms
|
||||||
|
unsigned int projectionLoc; // Projection matrix uniform location point (vertex shader)
|
||||||
|
unsigned int modelviewLoc; // ModeView matrix uniform location point (vertex shader)
|
||||||
|
unsigned int textureLoc; // Texture uniform location point (fragment shader)
|
||||||
|
unsigned int tintColorLoc; // Color uniform location point (fragment shader)
|
||||||
|
} Shader;
|
||||||
|
|
||||||
// 3d Model type
|
// 3d Model type
|
||||||
// NOTE: If using OpenGL 1.1, loaded in CPU (mesh); if OpenGL 3.3+ loaded in GPU (vaoId)
|
// NOTE: If using OpenGL 1.1, loaded in CPU (mesh); if OpenGL 3.3+ loaded in GPU (vaoId)
|
||||||
typedef struct Model {
|
typedef struct Model {
|
||||||
VertexData mesh;
|
VertexData mesh;
|
||||||
unsigned int vaoId;
|
unsigned int vaoId;
|
||||||
unsigned int vboId[4];
|
unsigned int vboId[4];
|
||||||
unsigned int textureId;
|
Texture2D texture;
|
||||||
unsigned int shaderId;
|
Shader shader;
|
||||||
//Matrix transform;
|
//Matrix transform;
|
||||||
} Model;
|
} Model;
|
||||||
|
|
||||||
// Shader type
|
|
||||||
typedef struct Shader {
|
|
||||||
unsigned int id;
|
|
||||||
} Shader;
|
|
||||||
|
|
||||||
// Sound source type
|
// Sound source type
|
||||||
typedef struct Sound {
|
typedef struct Sound {
|
||||||
unsigned int source;
|
unsigned int source;
|
||||||
|
@ -343,13 +355,13 @@ int GetRandomValue(int min, int max); // Returns a random
|
||||||
Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f
|
Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f
|
||||||
|
|
||||||
void SetCameraMode(int mode); // Multiple camera modes available
|
void SetCameraMode(int mode); // Multiple camera modes available
|
||||||
void UpdateCamera(Vector3 *playerPosition);
|
void UpdateCamera(Vector3 *playerPosition); // Update camera with player position (when using internal camera)
|
||||||
|
|
||||||
void SetConfigFlags(char flags); // Enable some window configurations
|
void SetConfigFlags(char flags); // Enable some window configurations
|
||||||
void ShowLogo(void); // Activates raylib logo at startup (can be done with flags)
|
void ShowLogo(void); // Activates raylib logo at startup (can be done with flags)
|
||||||
|
|
||||||
void InitPostShader(void);
|
void InitPostShader(void); // Initialize fullscreen postproduction shaders system
|
||||||
void SetPostShader(unsigned int shader);
|
void SetPostShader(unsigned int shader); // Set fullscreen postproduction shader
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Input Handling Functions (Module: core)
|
// Input Handling Functions (Module: core)
|
||||||
|
@ -487,7 +499,7 @@ Model LoadHeightmap(Image heightmap, float maxHeight);
|
||||||
Model LoadCubicmap(Image cubicmap); // Load a map image as a 3d model (cubes based)
|
Model LoadCubicmap(Image cubicmap); // Load a map image as a 3d model (cubes based)
|
||||||
void UnloadModel(Model model); // Unload 3d model from memory
|
void UnloadModel(Model model); // Unload 3d model from memory
|
||||||
void SetModelTexture(Model *model, Texture2D texture); // Link a texture to a model
|
void SetModelTexture(Model *model, Texture2D texture); // Link a texture to a model
|
||||||
void SetModelShader(Model *model, unsigned int shader);
|
void SetModelShader(Model *model, Shader shader); // Link a shader to a model (not available on OpenGL 1.1)
|
||||||
|
|
||||||
void DrawModel(Model model, Vector3 position, float scale, Color tint); // Draw a model (with texture if set)
|
void DrawModel(Model model, Vector3 position, float scale, Color tint); // Draw a model (with texture if set)
|
||||||
void DrawModelEx(Model model, Vector3 position, Vector3 rotation, Vector3 scale, Color tint); // Draw a model with extended parameters
|
void DrawModelEx(Model model, Vector3 position, Vector3 rotation, Vector3 scale, Color tint); // Draw a model with extended parameters
|
||||||
|
@ -496,7 +508,7 @@ void DrawModelWires(Model model, Vector3 position, float scale, Color color);
|
||||||
void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint); // Draw a billboard texture
|
void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint); // Draw a billboard texture
|
||||||
void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 center, float size, Color tint); // Draw a billboard texture defined by sourceRec
|
void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 center, float size, Color tint); // Draw a billboard texture defined by sourceRec
|
||||||
|
|
||||||
unsigned int LoadCustomShader(char *vsFileName, char *fsFileName); // Load a custom shader (vertex shader + fragment shader)
|
Shader LoadShader(char *vsFileName, char *fsFileName); // Load a custom shader (vertex shader + fragment shader)
|
||||||
|
|
||||||
bool CheckCollisionSpheres(Vector3 centerA, float radiusA, Vector3 centerB, float radiusB);
|
bool CheckCollisionSpheres(Vector3 centerA, float radiusA, Vector3 centerB, float radiusB);
|
||||||
bool CheckCollisionBoxes(Vector3 minBBox1, Vector3 maxBBox1, Vector3 minBBox2, Vector3 maxBBox2);
|
bool CheckCollisionBoxes(Vector3 minBBox1, Vector3 maxBBox1, Vector3 minBBox2, Vector3 maxBBox2);
|
||||||
|
|
350
src/rlgl.c
350
src/rlgl.c
|
@ -151,24 +151,8 @@ static VertexPositionColorBuffer lines; // No texture support
|
||||||
static VertexPositionColorBuffer triangles; // No texture support
|
static VertexPositionColorBuffer triangles; // No texture support
|
||||||
static VertexPositionColorTextureIndexBuffer quads;
|
static VertexPositionColorTextureIndexBuffer quads;
|
||||||
|
|
||||||
// Vetex-Fragment Shader Program ID
|
// Shader Programs
|
||||||
static GLuint defaultShaderProgram, simpleShaderProgram;
|
static Shader defaultShader, simpleShader;
|
||||||
|
|
||||||
// Default Shader program attibutes binding locations
|
|
||||||
static GLuint defaultVertexLoc, defaultTexcoordLoc, defaultColorLoc;
|
|
||||||
static GLuint defaultProjectionMatrixLoc, defaultModelviewMatrixLoc;
|
|
||||||
static GLuint defaultTextureLoc;
|
|
||||||
|
|
||||||
// Simple Shader program attibutes binding locations
|
|
||||||
static GLuint simpleVertexLoc, simpleTexcoordLoc, simpleNormalLoc, simpleColorLoc;
|
|
||||||
static GLuint simpleProjectionMatrixLoc, simpleModelviewMatrixLoc;
|
|
||||||
static GLuint simpleTextureLoc;
|
|
||||||
|
|
||||||
// Custom Shader program attibutes binding locations
|
|
||||||
static GLuint customVertexLoc, customTexcoordLoc, customNormalLoc, customColorLoc;
|
|
||||||
static GLuint customProjectionMatrixLoc, customModelviewMatrixLoc;
|
|
||||||
static GLuint customTextureLoc;
|
|
||||||
static bool customShader = false;
|
|
||||||
|
|
||||||
// Vertex Array Objects (VAO)
|
// Vertex Array Objects (VAO)
|
||||||
static GLuint vaoLines, vaoTriangles, vaoQuads;
|
static GLuint vaoLines, vaoTriangles, vaoQuads;
|
||||||
|
@ -210,8 +194,8 @@ unsigned int whiteTexture;
|
||||||
// Module specific Functions Declaration
|
// Module specific Functions Declaration
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
static GLuint LoadDefaultShader(void);
|
static Shader LoadDefaultShader(void);
|
||||||
static GLuint LoadSimpleShader(void);
|
static Shader LoadSimpleShader(void);
|
||||||
static void InitializeBuffers(void);
|
static void InitializeBuffers(void);
|
||||||
static void InitializeBuffersGPU(void);
|
static void InitializeBuffersGPU(void);
|
||||||
static void UpdateBuffers(void);
|
static void UpdateBuffers(void);
|
||||||
|
@ -704,6 +688,7 @@ void rlDeleteTextures(unsigned int id)
|
||||||
glDeleteTextures(1, &id);
|
glDeleteTextures(1, &id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
// Unload shader from GPU memory
|
// Unload shader from GPU memory
|
||||||
void rlDeleteShader(unsigned int id)
|
void rlDeleteShader(unsigned int id)
|
||||||
{
|
{
|
||||||
|
@ -714,6 +699,7 @@ void rlEnableFBO(void)
|
||||||
{
|
{
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Unload vertex data (VAO) from GPU memory
|
// Unload vertex data (VAO) from GPU memory
|
||||||
void rlDeleteVertexArrays(unsigned int id)
|
void rlDeleteVertexArrays(unsigned int id)
|
||||||
|
@ -868,39 +854,9 @@ void rlglInit(void)
|
||||||
for (int i = 0; i < MATRIX_STACK_SIZE; i++) stack[i] = MatrixIdentity();
|
for (int i = 0; i < MATRIX_STACK_SIZE; i++) stack[i] = MatrixIdentity();
|
||||||
|
|
||||||
// Init default Shader (GLSL 110) -> Common for GL 3.3+ and ES2
|
// Init default Shader (GLSL 110) -> Common for GL 3.3+ and ES2
|
||||||
defaultShaderProgram = LoadDefaultShader();
|
defaultShader = LoadDefaultShader();
|
||||||
simpleShaderProgram = LoadSimpleShader();
|
simpleShader = LoadSimpleShader();
|
||||||
//simpleShaderProgram = LoadCustomShader("custom.vs", "custom.fs"); // Works ok
|
//customShader = LoadShader("custom.vs", "custom.fs"); // Works ok
|
||||||
//customShaderProgram = LoadCustomShader("simple150.vert", "simple150.frag");
|
|
||||||
|
|
||||||
// Get handles to GLSL input vars locations for defaultShaderProgram
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
defaultVertexLoc = glGetAttribLocation(defaultShaderProgram, "vertexPosition");
|
|
||||||
defaultTexcoordLoc = glGetAttribLocation(defaultShaderProgram, "vertexTexCoord");
|
|
||||||
defaultColorLoc = glGetAttribLocation(defaultShaderProgram, "vertexColor");
|
|
||||||
|
|
||||||
// Get handles to GLSL uniform vars locations (vertex-shader)
|
|
||||||
defaultModelviewMatrixLoc = glGetUniformLocation(defaultShaderProgram, "modelviewMatrix");
|
|
||||||
defaultProjectionMatrixLoc = glGetUniformLocation(defaultShaderProgram, "projectionMatrix");
|
|
||||||
|
|
||||||
// Get handles to GLSL uniform vars locations (fragment-shader)
|
|
||||||
defaultTextureLoc = glGetUniformLocation(defaultShaderProgram, "texture0");
|
|
||||||
//--------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Get handles to GLSL input vars locations for simpleShaderProgram
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
simpleVertexLoc = glGetAttribLocation(simpleShaderProgram, "vertexPosition");
|
|
||||||
simpleTexcoordLoc = glGetAttribLocation(simpleShaderProgram, "vertexTexCoord");
|
|
||||||
simpleNormalLoc = glGetAttribLocation(defaultShaderProgram, "vertexNormal");
|
|
||||||
|
|
||||||
// Get handles to GLSL uniform vars locations (vertex-shader)
|
|
||||||
simpleModelviewMatrixLoc = glGetUniformLocation(simpleShaderProgram, "modelviewMatrix");
|
|
||||||
simpleProjectionMatrixLoc = glGetUniformLocation(simpleShaderProgram, "projectionMatrix");
|
|
||||||
|
|
||||||
// Get handles to GLSL uniform vars locations (fragment-shader)
|
|
||||||
simpleTextureLoc = glGetUniformLocation(simpleShaderProgram, "texture0");
|
|
||||||
simpleColorLoc = glGetUniformLocation(simpleShaderProgram, "fragColor");
|
|
||||||
//--------------------------------------------------------------------
|
|
||||||
|
|
||||||
InitializeBuffers(); // Init vertex arrays
|
InitializeBuffers(); // Init vertex arrays
|
||||||
InitializeBuffersGPU(); // Init VBO and VAO
|
InitializeBuffersGPU(); // Init VBO and VAO
|
||||||
|
@ -913,7 +869,7 @@ void rlglInit(void)
|
||||||
// Create default white texture for plain colors (required by shader)
|
// Create default white texture for plain colors (required by shader)
|
||||||
unsigned char pixels[4] = { 255, 255, 255, 255 }; // 1 pixel RGBA (4 bytes)
|
unsigned char pixels[4] = { 255, 255, 255, 255 }; // 1 pixel RGBA (4 bytes)
|
||||||
|
|
||||||
whiteTexture = rlglLoadTexture(pixels, 1, 1, false);
|
whiteTexture = rlglLoadTexture(pixels, 1, 1, R8G8B8A8, false);
|
||||||
|
|
||||||
if (whiteTexture != 0) TraceLog(INFO, "[TEX ID %i] Base white texture loaded successfully", whiteTexture);
|
if (whiteTexture != 0) TraceLog(INFO, "[TEX ID %i] Base white texture loaded successfully", whiteTexture);
|
||||||
else TraceLog(WARNING, "Base white texture could not be loaded");
|
else TraceLog(WARNING, "Base white texture could not be loaded");
|
||||||
|
@ -932,6 +888,7 @@ void rlglInit(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
// Init postpro system
|
// Init postpro system
|
||||||
void rlglInitPostpro(void)
|
void rlglInitPostpro(void)
|
||||||
{
|
{
|
||||||
|
@ -959,7 +916,7 @@ void rlglInitPostpro(void)
|
||||||
glGenFramebuffers(1, &fbo);
|
glGenFramebuffers(1, &fbo);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||||
|
|
||||||
// Attach colort texture and depth texture to FBO
|
// Attach color texture and depth texture to FBO
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fboColorTexture, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fboColorTexture, 0);
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, fboDepthTexture, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, fboDepthTexture, 0);
|
||||||
|
|
||||||
|
@ -974,6 +931,7 @@ void rlglInitPostpro(void)
|
||||||
|
|
||||||
// TODO: Init simple quad VAO and data here?
|
// TODO: Init simple quad VAO and data here?
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Vertex Buffer Object deinitialization (memory free)
|
// Vertex Buffer Object deinitialization (memory free)
|
||||||
void rlglClose(void)
|
void rlglClose(void)
|
||||||
|
@ -1012,8 +970,8 @@ void rlglClose(void)
|
||||||
//glDetachShader(defaultShaderProgram, f);
|
//glDetachShader(defaultShaderProgram, f);
|
||||||
//glDeleteShader(v);
|
//glDeleteShader(v);
|
||||||
//glDeleteShader(f);
|
//glDeleteShader(f);
|
||||||
glDeleteProgram(defaultShaderProgram);
|
glDeleteProgram(defaultShader.id);
|
||||||
glDeleteProgram(simpleShaderProgram);
|
glDeleteProgram(simpleShader.id);
|
||||||
|
|
||||||
// Free vertex arrays memory
|
// Free vertex arrays memory
|
||||||
free(lines.vertices);
|
free(lines.vertices);
|
||||||
|
@ -1043,14 +1001,11 @@ void rlglDraw(void)
|
||||||
|
|
||||||
if ((lines.vCounter > 0) || (triangles.vCounter > 0) || (quads.vCounter > 0))
|
if ((lines.vCounter > 0) || (triangles.vCounter > 0) || (quads.vCounter > 0))
|
||||||
{
|
{
|
||||||
if (fbo == 0) glUseProgram(defaultShaderProgram); // Use our default shader
|
glUseProgram(defaultShader.id);
|
||||||
else glUseProgram(fboShader); // Use our postpro shader
|
|
||||||
|
|
||||||
glUseProgram(defaultShaderProgram);
|
glUniformMatrix4fv(defaultShader.projectionLoc, 1, false, GetMatrixVector(projection));
|
||||||
|
glUniformMatrix4fv(defaultShader.modelviewLoc, 1, false, GetMatrixVector(modelview));
|
||||||
glUniformMatrix4fv(defaultProjectionMatrixLoc, 1, false, GetMatrixVector(projection));
|
glUniform1i(defaultShader.textureLoc, 0);
|
||||||
glUniformMatrix4fv(defaultModelviewMatrixLoc, 1, false, GetMatrixVector(modelview));
|
|
||||||
glUniform1i(defaultTextureLoc, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: We draw in this order: triangle shapes, textured quads and lines
|
// NOTE: We draw in this order: triangle shapes, textured quads and lines
|
||||||
|
@ -1066,12 +1021,12 @@ void rlglDraw(void)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, trianglesBuffer[0]);
|
glBindBuffer(GL_ARRAY_BUFFER, trianglesBuffer[0]);
|
||||||
glVertexAttribPointer(defaultVertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
glVertexAttribPointer(defaultShader.vertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||||
glEnableVertexAttribArray(defaultVertexLoc);
|
glEnableVertexAttribArray(defaultShader.vertexLoc);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, trianglesBuffer[1]);
|
glBindBuffer(GL_ARRAY_BUFFER, trianglesBuffer[1]);
|
||||||
glVertexAttribPointer(defaultColorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
glVertexAttribPointer(defaultShader.colorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
||||||
glEnableVertexAttribArray(defaultColorLoc);
|
glEnableVertexAttribArray(defaultShader.colorLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, triangles.vCounter);
|
glDrawArrays(GL_TRIANGLES, 0, triangles.vCounter);
|
||||||
|
@ -1094,16 +1049,16 @@ void rlglDraw(void)
|
||||||
{
|
{
|
||||||
// Enable vertex attributes
|
// Enable vertex attributes
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, quadsBuffer[0]);
|
glBindBuffer(GL_ARRAY_BUFFER, quadsBuffer[0]);
|
||||||
glVertexAttribPointer(defaultVertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
glVertexAttribPointer(defaultShader.vertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||||
glEnableVertexAttribArray(defaultVertexLoc);
|
glEnableVertexAttribArray(defaultShader.vertexLoc);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, quadsBuffer[1]);
|
glBindBuffer(GL_ARRAY_BUFFER, quadsBuffer[1]);
|
||||||
glVertexAttribPointer(defaultTexcoordLoc, 2, GL_FLOAT, 0, 0, 0);
|
glVertexAttribPointer(defaultShader.texcoordLoc, 2, GL_FLOAT, 0, 0, 0);
|
||||||
glEnableVertexAttribArray(defaultTexcoordLoc);
|
glEnableVertexAttribArray(defaultShader.texcoordLoc);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, quadsBuffer[2]);
|
glBindBuffer(GL_ARRAY_BUFFER, quadsBuffer[2]);
|
||||||
glVertexAttribPointer(defaultColorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
glVertexAttribPointer(defaultShader.colorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
||||||
glEnableVertexAttribArray(defaultColorLoc);
|
glEnableVertexAttribArray(defaultShader.colorLoc);
|
||||||
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, quadsBuffer[3]);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, quadsBuffer[3]);
|
||||||
}
|
}
|
||||||
|
@ -1151,12 +1106,12 @@ void rlglDraw(void)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, linesBuffer[0]);
|
glBindBuffer(GL_ARRAY_BUFFER, linesBuffer[0]);
|
||||||
glVertexAttribPointer(defaultVertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
glVertexAttribPointer(defaultShader.vertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||||
glEnableVertexAttribArray(defaultVertexLoc);
|
glEnableVertexAttribArray(defaultShader.vertexLoc);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, linesBuffer[1]);
|
glBindBuffer(GL_ARRAY_BUFFER, linesBuffer[1]);
|
||||||
glVertexAttribPointer(defaultColorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
glVertexAttribPointer(defaultShader.colorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
||||||
glEnableVertexAttribArray(defaultColorLoc);
|
glEnableVertexAttribArray(defaultShader.colorLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
glDrawArrays(GL_LINES, 0, lines.vCounter);
|
glDrawArrays(GL_LINES, 0, lines.vCounter);
|
||||||
|
@ -1167,6 +1122,8 @@ void rlglDraw(void)
|
||||||
|
|
||||||
if (vaoSupported) glBindVertexArray(0); // Unbind VAO
|
if (vaoSupported) glBindVertexArray(0); // Unbind VAO
|
||||||
|
|
||||||
|
glUseProgram(0); // Unbind shader program
|
||||||
|
|
||||||
// Reset draws counter
|
// Reset draws counter
|
||||||
drawsCounter = 1;
|
drawsCounter = 1;
|
||||||
draws[0].textureId = whiteTexture;
|
draws[0].textureId = whiteTexture;
|
||||||
|
@ -1185,6 +1142,7 @@ void rlglDraw(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
void rlglDrawPostpro(unsigned int shaderId)
|
void rlglDrawPostpro(unsigned int shaderId)
|
||||||
{
|
{
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
@ -1245,6 +1203,7 @@ void rlglDrawPostpro(unsigned int shaderId)
|
||||||
|
|
||||||
rlglDraw();
|
rlglDraw();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Draw a 3d model
|
// Draw a 3d model
|
||||||
void rlglDrawModel(Model model, Vector3 position, Vector3 rotation, Vector3 scale, Color color, bool wires)
|
void rlglDrawModel(Model model, Vector3 position, Vector3 rotation, Vector3 scale, Color color, bool wires)
|
||||||
|
@ -1289,35 +1248,26 @@ void rlglDrawModel(Model model, Vector3 position, Vector3 rotation, Vector3 scal
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
if (customShader) glUseProgram(model.shaderId);
|
glUseProgram(model.shader.id);
|
||||||
else glUseProgram(simpleShaderProgram); // Use our simple shader
|
|
||||||
|
|
||||||
VectorScale(&rotation, DEG2RAD);
|
VectorScale(&rotation, DEG2RAD);
|
||||||
|
|
||||||
// Get transform matrix (rotation -> scale -> translation)
|
// Get transform matrix (rotation -> scale -> translation)
|
||||||
Matrix transform = MatrixTransform(position, rotation, scale);
|
Matrix transform = MatrixTransform(position, rotation, scale); // Object-space transformation
|
||||||
Matrix modelviewworld = MatrixMultiply(transform, modelview);
|
Matrix modelviewworld = MatrixMultiply(transform, modelview); // World-space transformation
|
||||||
|
|
||||||
|
// Projection: Screen-space transformation
|
||||||
|
|
||||||
// NOTE: Drawing in OpenGL 3.3+, transform is passed to shader
|
// NOTE: Drawing in OpenGL 3.3+, transform is passed to shader
|
||||||
if (customShader)
|
glUniformMatrix4fv(model.shader.projectionLoc, 1, false, GetMatrixVector(projection));
|
||||||
{
|
glUniformMatrix4fv(model.shader.modelviewLoc, 1, false, GetMatrixVector(modelviewworld));
|
||||||
glUniformMatrix4fv(customProjectionMatrixLoc, 1, false, GetMatrixVector(projection));
|
glUniform1i(model.shader.textureLoc, 0);
|
||||||
glUniformMatrix4fv(customModelviewMatrixLoc, 1, false, GetMatrixVector(modelviewworld));
|
|
||||||
glUniform1i(customTextureLoc, 0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
glUniformMatrix4fv(simpleProjectionMatrixLoc, 1, false, GetMatrixVector(projection));
|
|
||||||
glUniformMatrix4fv(simpleModelviewMatrixLoc, 1, false, GetMatrixVector(modelviewworld));
|
|
||||||
glUniform1i(simpleTextureLoc, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply color tinting to model
|
// Apply color tinting to model
|
||||||
// NOTE: Just update one uniform on fragment shader
|
// NOTE: Just update one uniform on fragment shader
|
||||||
float vColor[4] = { (float)color.r/255, (float)color.g/255, (float)color.b/255, (float)color.a/255 };
|
float vColor[4] = { (float)color.r/255, (float)color.g/255, (float)color.b/255, (float)color.a/255 };
|
||||||
|
|
||||||
if (customShader) glUniform4fv(customColorLoc, 1, vColor);
|
glUniform4fv(model.shader.tintColorLoc, 1, vColor);
|
||||||
else glUniform4fv(simpleColorLoc, 1, vColor);
|
|
||||||
|
|
||||||
if (vaoSupported)
|
if (vaoSupported)
|
||||||
{
|
{
|
||||||
|
@ -1327,20 +1277,20 @@ void rlglDrawModel(Model model, Vector3 position, Vector3 rotation, Vector3 scal
|
||||||
{
|
{
|
||||||
// Bind model VBOs data
|
// Bind model VBOs data
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, model.vboId[0]);
|
glBindBuffer(GL_ARRAY_BUFFER, model.vboId[0]);
|
||||||
glVertexAttribPointer(simpleVertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
glVertexAttribPointer(model.shader.vertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||||
glEnableVertexAttribArray(simpleVertexLoc);
|
glEnableVertexAttribArray(model.shader.vertexLoc);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, model.vboId[1]);
|
glBindBuffer(GL_ARRAY_BUFFER, model.vboId[1]);
|
||||||
glVertexAttribPointer(simpleTexcoordLoc, 2, GL_FLOAT, 0, 0, 0);
|
glVertexAttribPointer(model.shader.texcoordLoc, 2, GL_FLOAT, 0, 0, 0);
|
||||||
glEnableVertexAttribArray(simpleTexcoordLoc);
|
glEnableVertexAttribArray(model.shader.texcoordLoc);
|
||||||
|
|
||||||
// Add normals support
|
// Add normals support
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, model.vboId[2]);
|
glBindBuffer(GL_ARRAY_BUFFER, model.vboId[2]);
|
||||||
glVertexAttribPointer(simpleNormalLoc, 3, GL_FLOAT, 0, 0, 0);
|
glVertexAttribPointer(model.shader.normalLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||||
glEnableVertexAttribArray(simpleNormalLoc);
|
glEnableVertexAttribArray(model.shader.normalLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, model.textureId);
|
glBindTexture(GL_TEXTURE_2D, model.texture.id);
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, model.mesh.vertexCount);
|
glDrawArrays(GL_TRIANGLES, 0, model.mesh.vertexCount);
|
||||||
|
|
||||||
|
@ -1406,7 +1356,7 @@ void rlglInitGraphics(int offsetX, int offsetY, int width, int height)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert image data to OpenGL texture (returns OpenGL valid Id)
|
// Convert image data to OpenGL texture (returns OpenGL valid Id)
|
||||||
unsigned int rlglLoadTexture(unsigned char *data, int width, int height, bool genMipmaps)
|
unsigned int rlglLoadTexture(unsigned char *data, int width, int height, int colorMode, bool genMipmaps)
|
||||||
{
|
{
|
||||||
glBindTexture(GL_TEXTURE_2D,0); // Free any old binding
|
glBindTexture(GL_TEXTURE_2D,0); // Free any old binding
|
||||||
|
|
||||||
|
@ -1482,7 +1432,7 @@ unsigned int rlglLoadTexture(unsigned char *data, int width, int height, bool ge
|
||||||
// NOTE: We define internal (GPU) format as GL_RGBA8 (probably BGRA8 in practice, driver takes care)
|
// NOTE: We define internal (GPU) format as GL_RGBA8 (probably BGRA8 in practice, driver takes care)
|
||||||
// NOTE: On embedded systems, we let the driver choose the best internal format
|
// NOTE: On embedded systems, we let the driver choose the best internal format
|
||||||
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); // OpenGL
|
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); // OpenGL
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); // WebGL
|
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); // WebGL
|
||||||
|
|
||||||
// TODO: Add support for multiple color modes (16bit color modes and grayscale)
|
// TODO: Add support for multiple color modes (16bit color modes and grayscale)
|
||||||
// Ref: https://www.khronos.org/opengles/sdk/docs/man3/html/glTexImage2D.xhtml
|
// Ref: https://www.khronos.org/opengles/sdk/docs/man3/html/glTexImage2D.xhtml
|
||||||
|
@ -1495,6 +1445,17 @@ unsigned int rlglLoadTexture(unsigned char *data, int width, int height, bool ge
|
||||||
// GL_RGBA8 GL_RGBA GL_UNSIGNED_BYTE
|
// GL_RGBA8 GL_RGBA GL_UNSIGNED_BYTE
|
||||||
// GL_RGB8 GL_RGB GL_UNSIGNED_BYTE
|
// GL_RGB8 GL_RGB GL_UNSIGNED_BYTE
|
||||||
|
|
||||||
|
switch (colorMode)
|
||||||
|
{
|
||||||
|
case GRAYSCALE: glTexImage2D(GL_TEXTURE_2D, 0, GL_R, width, height, 0, GL_RED, GL_UNSIGNED_BYTE, data); break;
|
||||||
|
case R5G6B5: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB565, width, height, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, data); break;
|
||||||
|
case R8G8B8: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); break;
|
||||||
|
case R5G5B5A1: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB5_A1, width, height, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, data); break;
|
||||||
|
case R4G4B4A4: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA4, width, height, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, data); break;
|
||||||
|
case R8G8B8A8: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); break;
|
||||||
|
default: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); break;
|
||||||
|
}
|
||||||
|
|
||||||
if (genMipmaps)
|
if (genMipmaps)
|
||||||
{
|
{
|
||||||
glGenerateMipmap(GL_TEXTURE_2D); // Generate mipmaps automatically
|
glGenerateMipmap(GL_TEXTURE_2D); // Generate mipmaps automatically
|
||||||
|
@ -1520,17 +1481,19 @@ Model rlglLoadModel(VertexData mesh)
|
||||||
model.mesh = mesh;
|
model.mesh = mesh;
|
||||||
|
|
||||||
#if defined(GRAPHICS_API_OPENGL_11)
|
#if defined(GRAPHICS_API_OPENGL_11)
|
||||||
model.textureId = 0; // No texture required
|
model.texture.id = 0; // No texture required
|
||||||
model.vaoId = 0; // Vertex Array Object
|
model.vaoId = 0; // Vertex Array Object
|
||||||
model.vboId[0] = 0; // Vertex position VBO
|
model.vboId[0] = 0; // Vertex position VBO
|
||||||
model.vboId[1] = 0; // Texcoords VBO
|
model.vboId[1] = 0; // Texcoords VBO
|
||||||
model.vboId[2] = 0; // Normals VBO
|
model.vboId[2] = 0; // Normals VBO
|
||||||
|
|
||||||
#elif defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
#elif defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
model.textureId = whiteTexture; // Default whiteTexture
|
model.texture.id = whiteTexture; // Default whiteTexture
|
||||||
|
model.texture.width = 1; // Default whiteTexture width
|
||||||
|
model.texture.height = 1; // Default whiteTexture height
|
||||||
|
|
||||||
GLuint vaoModel = 0; // Vertex Array Objects (VAO)
|
GLuint vaoModel = 0; // Vertex Array Objects (VAO)
|
||||||
GLuint vertexBuffer[3]; // Vertex Buffer Objects (VBO)
|
GLuint vertexBuffer[3]; // Vertex Buffer Objects (VBO)
|
||||||
|
|
||||||
if (vaoSupported)
|
if (vaoSupported)
|
||||||
{
|
{
|
||||||
|
@ -1545,20 +1508,22 @@ Model rlglLoadModel(VertexData mesh)
|
||||||
// Enable vertex attributes: position
|
// Enable vertex attributes: position
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer[0]);
|
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer[0]);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*mesh.vertexCount, mesh.vertices, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*mesh.vertexCount, mesh.vertices, GL_STATIC_DRAW);
|
||||||
glEnableVertexAttribArray(simpleVertexLoc);
|
glEnableVertexAttribArray(simpleShader.vertexLoc);
|
||||||
glVertexAttribPointer(simpleVertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
glVertexAttribPointer(simpleShader.vertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||||
|
|
||||||
// Enable vertex attributes: texcoords
|
// Enable vertex attributes: texcoords
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer[1]);
|
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer[1]);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*mesh.vertexCount, mesh.texcoords, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*mesh.vertexCount, mesh.texcoords, GL_STATIC_DRAW);
|
||||||
glEnableVertexAttribArray(simpleTexcoordLoc);
|
glEnableVertexAttribArray(simpleShader.texcoordLoc);
|
||||||
glVertexAttribPointer(simpleTexcoordLoc, 2, GL_FLOAT, 0, 0, 0);
|
glVertexAttribPointer(simpleShader.texcoordLoc, 2, GL_FLOAT, 0, 0, 0);
|
||||||
|
|
||||||
// Enable vertex attributes: normals
|
// Enable vertex attributes: normals
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer[2]);
|
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer[2]);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*mesh.vertexCount, mesh.normals, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*mesh.vertexCount, mesh.normals, GL_STATIC_DRAW);
|
||||||
glEnableVertexAttribArray(simpleNormalLoc);
|
glEnableVertexAttribArray(simpleShader.normalLoc);
|
||||||
glVertexAttribPointer(simpleNormalLoc, 3, GL_FLOAT, 0, 0, 0);
|
glVertexAttribPointer(simpleShader.normalLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||||
|
|
||||||
|
model.shader = simpleShader; // By default, simple shader will be used
|
||||||
|
|
||||||
model.vboId[0] = vertexBuffer[0]; // Vertex position VBO
|
model.vboId[0] = vertexBuffer[0]; // Vertex position VBO
|
||||||
model.vboId[1] = vertexBuffer[1]; // Texcoords VBO
|
model.vboId[1] = vertexBuffer[1]; // Texcoords VBO
|
||||||
|
@ -1661,6 +1626,7 @@ unsigned int rlglLoadCompressedTexture(unsigned char *data, int width, int heigh
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
// Load a shader (vertex shader + fragment shader) from text data
|
// Load a shader (vertex shader + fragment shader) from text data
|
||||||
unsigned int rlglLoadShader(char *vShaderStr, char *fShaderStr)
|
unsigned int rlglLoadShader(char *vShaderStr, char *fShaderStr)
|
||||||
{
|
{
|
||||||
|
@ -1756,6 +1722,7 @@ unsigned int rlglLoadShader(char *vShaderStr, char *fShaderStr)
|
||||||
|
|
||||||
return program;
|
return program;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Read screen pixel data (color buffer)
|
// Read screen pixel data (color buffer)
|
||||||
unsigned char *rlglReadScreenPixels(int width, int height)
|
unsigned char *rlglReadScreenPixels(int width, int height)
|
||||||
|
@ -1781,68 +1748,69 @@ unsigned char *rlglReadScreenPixels(int width, int height)
|
||||||
return imgData; // NOTE: image data should be freed
|
return imgData; // NOTE: image data should be freed
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int LoadCustomShader(char *vsFileName, char *fsFileName)
|
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
|
// Load a shader (vertex shader + fragment shader) from text data
|
||||||
|
Shader LoadShader(char *vsFileName, char *fsFileName)
|
||||||
{
|
{
|
||||||
|
Shader shader;
|
||||||
|
|
||||||
// Shaders loading from external text file
|
// Shaders loading from external text file
|
||||||
char *vShaderStr = TextFileRead(vsFileName);
|
char *vShaderStr = TextFileRead(vsFileName);
|
||||||
char *fShaderStr = TextFileRead(fsFileName);
|
char *fShaderStr = TextFileRead(fsFileName);
|
||||||
|
|
||||||
unsigned int shaderId = rlglLoadShader(vShaderStr, fShaderStr);
|
shader.id = rlglLoadShader(vShaderStr, fShaderStr);
|
||||||
|
|
||||||
if (shaderId != 0) TraceLog(INFO, "[SHDR ID %i] Custom shader loaded successfully", shaderId);
|
if (shader.id != 0) TraceLog(INFO, "[SHDR ID %i] Custom shader loaded successfully", shader.id);
|
||||||
else TraceLog(WARNING, "[SHDR ID %i] Custom shader could not be loaded", shaderId);
|
else TraceLog(WARNING, "[SHDR ID %i] Custom shader could not be loaded", shader.id);
|
||||||
|
|
||||||
return shaderId;
|
|
||||||
|
|
||||||
// Shader strings must be freed
|
// Shader strings must be freed
|
||||||
free(vShaderStr);
|
free(vShaderStr);
|
||||||
free(fShaderStr);
|
free(fShaderStr);
|
||||||
|
|
||||||
return shaderId;
|
// Get handles to GLSL input attibute locations
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
shader.vertexLoc = glGetAttribLocation(shader.id, "vertexPosition");
|
||||||
|
shader.texcoordLoc = glGetAttribLocation(shader.id, "vertexTexCoord");
|
||||||
|
shader.normalLoc = glGetAttribLocation(shader.id, "vertexNormal");
|
||||||
|
// NOTE: custom shader does not use colorLoc
|
||||||
|
|
||||||
|
// Get handles to GLSL uniform locations (vertex shader)
|
||||||
|
shader.modelviewLoc = glGetUniformLocation(shader.id, "modelviewMatrix");
|
||||||
|
shader.projectionLoc = glGetUniformLocation(shader.id, "projectionMatrix");
|
||||||
|
|
||||||
|
// Get handles to GLSL uniform locations (fragment shader)
|
||||||
|
shader.textureLoc = glGetUniformLocation(shader.id, "texture0");
|
||||||
|
shader.tintColorLoc = glGetUniformLocation(shader.id, "tintColor");
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
|
||||||
|
return shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Link shader to model
|
// Link shader to model
|
||||||
void SetModelShader(Model *model, unsigned int shader)
|
void SetModelShader(Model *model, Shader shader)
|
||||||
{
|
{
|
||||||
// Get handles to GLSL input vars locations for simpleShaderProgram
|
model->shader = shader;
|
||||||
customVertexLoc = glGetAttribLocation(shader, "vertexPosition");
|
|
||||||
customTexcoordLoc = glGetAttribLocation(shader, "vertexTexCoord");
|
|
||||||
customNormalLoc = glGetAttribLocation(shader, "vertexNormal");
|
|
||||||
|
|
||||||
// Get handles to GLSL uniform vars locations (vertex-shader)
|
|
||||||
customModelviewMatrixLoc = glGetUniformLocation(shader, "modelviewMatrix");
|
|
||||||
customProjectionMatrixLoc = glGetUniformLocation(shader, "projectionMatrix");
|
|
||||||
|
|
||||||
// Get handles to GLSL uniform vars locations (fragment-shader)
|
|
||||||
customTextureLoc = glGetUniformLocation(shader, "texture0");
|
|
||||||
customColorLoc = glGetUniformLocation(shader, "fragColor");
|
|
||||||
|
|
||||||
if (vaoSupported) glBindVertexArray(model->vaoId);
|
if (vaoSupported) glBindVertexArray(model->vaoId);
|
||||||
|
|
||||||
// Enable vertex attributes: position
|
// Enable vertex attributes: position
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, model->vboId[0]);
|
glBindBuffer(GL_ARRAY_BUFFER, model->vboId[0]);
|
||||||
glEnableVertexAttribArray(customVertexLoc);
|
glEnableVertexAttribArray(shader.vertexLoc);
|
||||||
glVertexAttribPointer(customVertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
glVertexAttribPointer(shader.vertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||||
|
|
||||||
// Enable vertex attributes: texcoords
|
// Enable vertex attributes: texcoords
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, model->vboId[1]);
|
glBindBuffer(GL_ARRAY_BUFFER, model->vboId[1]);
|
||||||
glEnableVertexAttribArray(customTexcoordLoc);
|
glEnableVertexAttribArray(shader.texcoordLoc);
|
||||||
glVertexAttribPointer(customTexcoordLoc, 2, GL_FLOAT, 0, 0, 0);
|
glVertexAttribPointer(shader.texcoordLoc, 2, GL_FLOAT, 0, 0, 0);
|
||||||
|
|
||||||
// Enable vertex attributes: normals
|
// Enable vertex attributes: normals
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, model->vboId[2]);
|
glBindBuffer(GL_ARRAY_BUFFER, model->vboId[2]);
|
||||||
glEnableVertexAttribArray(customNormalLoc);
|
glEnableVertexAttribArray(shader.normalLoc);
|
||||||
glVertexAttribPointer(customNormalLoc, 3, GL_FLOAT, 0, 0, 0);
|
glVertexAttribPointer(shader.normalLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||||
|
|
||||||
if (vaoSupported) glBindVertexArray(0); // Unbind VAO
|
if (vaoSupported) glBindVertexArray(0); // Unbind VAO
|
||||||
|
|
||||||
model->shaderId = shader;
|
|
||||||
|
|
||||||
customShader = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
||||||
|
|
||||||
void PrintProjectionMatrix()
|
void PrintProjectionMatrix()
|
||||||
{
|
{
|
||||||
PrintMatrix(projection);
|
PrintMatrix(projection);
|
||||||
|
@ -1863,8 +1831,10 @@ void PrintModelviewMatrix()
|
||||||
|
|
||||||
// Load Shader (Vertex and Fragment)
|
// Load Shader (Vertex and Fragment)
|
||||||
// NOTE: This shader program is used only for batch buffers (lines, triangles, quads)
|
// NOTE: This shader program is used only for batch buffers (lines, triangles, quads)
|
||||||
static GLuint LoadDefaultShader(void)
|
static Shader LoadDefaultShader(void)
|
||||||
{
|
{
|
||||||
|
Shader shader;
|
||||||
|
|
||||||
// NOTE: Shaders are written using GLSL 110 (desktop), that is equivalent to GLSL 100 on ES2
|
// NOTE: Shaders are written using GLSL 110 (desktop), that is equivalent to GLSL 100 on ES2
|
||||||
// NOTE: Detected an error on ATI cards if defined #version 110 while OpenGL 3.3+
|
// NOTE: Detected an error on ATI cards if defined #version 110 while OpenGL 3.3+
|
||||||
// Just defined #version 330 despite shader is #version 110
|
// Just defined #version 330 despite shader is #version 110
|
||||||
|
@ -1904,18 +1874,35 @@ static GLuint LoadDefaultShader(void)
|
||||||
" gl_FragColor = texture2D(texture0, fragTexCoord) * fragColor; \n"
|
" gl_FragColor = texture2D(texture0, fragTexCoord) * fragColor; \n"
|
||||||
"} \n";
|
"} \n";
|
||||||
|
|
||||||
unsigned int shaderId = rlglLoadShader(vShaderStr, fShaderStr);
|
shader.id = rlglLoadShader(vShaderStr, fShaderStr);
|
||||||
|
|
||||||
if (shaderId != 0) TraceLog(INFO, "[SHDR ID %i] Default shader loaded successfully", shaderId);
|
if (shader.id != 0) TraceLog(INFO, "[SHDR ID %i] Default shader loaded successfully", shader.id);
|
||||||
else TraceLog(WARNING, "[SHDR ID %i] Default shader could not be loaded", shaderId);
|
else TraceLog(WARNING, "[SHDR ID %i] Default shader could not be loaded", shader.id);
|
||||||
|
|
||||||
return shaderId;
|
// Get handles to GLSL input attibute locations
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
shader.vertexLoc = glGetAttribLocation(shader.id, "vertexPosition");
|
||||||
|
shader.texcoordLoc = glGetAttribLocation(shader.id, "vertexTexCoord");
|
||||||
|
shader.colorLoc = glGetAttribLocation(shader.id, "vertexColor");
|
||||||
|
// NOTE: default shader does not use normalLoc
|
||||||
|
|
||||||
|
// Get handles to GLSL uniform locations (vertex shader)
|
||||||
|
shader.modelviewLoc = glGetUniformLocation(shader.id, "modelviewMatrix");
|
||||||
|
shader.projectionLoc = glGetUniformLocation(shader.id, "projectionMatrix");
|
||||||
|
|
||||||
|
// Get handles to GLSL uniform locations (fragment shader)
|
||||||
|
shader.textureLoc = glGetUniformLocation(shader.id, "texture0");
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
|
||||||
|
return shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load Simple Shader (Vertex and Fragment)
|
// Load Simple Shader (Vertex and Fragment)
|
||||||
// NOTE: This shader program is used to render models
|
// NOTE: This shader program is used to render models
|
||||||
static GLuint LoadSimpleShader(void)
|
static Shader LoadSimpleShader(void)
|
||||||
{
|
{
|
||||||
|
Shader shader;
|
||||||
|
|
||||||
// NOTE: Shaders are written using GLSL 110 (desktop), that is equivalent to GLSL 100 on ES2
|
// NOTE: Shaders are written using GLSL 110 (desktop), that is equivalent to GLSL 100 on ES2
|
||||||
// NOTE: Detected an error on ATI cards if defined #version 110 while OpenGL 3.3+
|
// NOTE: Detected an error on ATI cards if defined #version 110 while OpenGL 3.3+
|
||||||
// Just defined #version 330 despite shader is #version 110
|
// Just defined #version 330 despite shader is #version 110
|
||||||
|
@ -1947,18 +1934,34 @@ static GLuint LoadSimpleShader(void)
|
||||||
#endif
|
#endif
|
||||||
"uniform sampler2D texture0; \n"
|
"uniform sampler2D texture0; \n"
|
||||||
"varying vec2 fragTexCoord; \n"
|
"varying vec2 fragTexCoord; \n"
|
||||||
"uniform vec4 fragColor; \n"
|
"uniform vec4 tintColor; \n"
|
||||||
"void main() \n"
|
"void main() \n"
|
||||||
"{ \n"
|
"{ \n"
|
||||||
" gl_FragColor = texture2D(texture0, fragTexCoord) * fragColor; \n"
|
" gl_FragColor = texture2D(texture0, fragTexCoord) * tintColor; \n"
|
||||||
"} \n";
|
"} \n";
|
||||||
|
|
||||||
unsigned int shaderId = rlglLoadShader(vShaderStr, fShaderStr);
|
shader.id = rlglLoadShader(vShaderStr, fShaderStr);
|
||||||
|
|
||||||
if (shaderId != 0) TraceLog(INFO, "[SHDR ID %i] Simple shader loaded successfully", shaderId);
|
if (shader.id != 0) TraceLog(INFO, "[SHDR ID %i] Simple shader loaded successfully", shader.id);
|
||||||
else TraceLog(WARNING, "[SHDR ID %i] Simple shader could not be loaded", shaderId);
|
else TraceLog(WARNING, "[SHDR ID %i] Simple shader could not be loaded", shader.id);
|
||||||
|
|
||||||
return shaderId;
|
// Get handles to GLSL input attibute locations
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
shader.vertexLoc = glGetAttribLocation(shader.id, "vertexPosition");
|
||||||
|
shader.texcoordLoc = glGetAttribLocation(shader.id, "vertexTexCoord");
|
||||||
|
shader.normalLoc = glGetAttribLocation(shader.id, "vertexNormal");
|
||||||
|
// NOTE: simple shader does not use colorLoc
|
||||||
|
|
||||||
|
// Get handles to GLSL uniform locations (vertex shader)
|
||||||
|
shader.modelviewLoc = glGetUniformLocation(shader.id, "modelviewMatrix");
|
||||||
|
shader.projectionLoc = glGetUniformLocation(shader.id, "projectionMatrix");
|
||||||
|
|
||||||
|
// Get handles to GLSL uniform locations (fragment shader)
|
||||||
|
shader.textureLoc = glGetUniformLocation(shader.id, "texture0");
|
||||||
|
shader.tintColorLoc = glGetUniformLocation(shader.id, "tintColor");
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
|
||||||
|
return shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read text file
|
// Read text file
|
||||||
|
@ -2056,6 +2059,7 @@ static void InitializeBuffers(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize Vertex Array Objects (Contain VBO)
|
// Initialize Vertex Array Objects (Contain VBO)
|
||||||
|
// NOTE: lines, triangles and quads buffers use defaultShader
|
||||||
static void InitializeBuffersGPU(void)
|
static void InitializeBuffersGPU(void)
|
||||||
{
|
{
|
||||||
if (vaoSupported)
|
if (vaoSupported)
|
||||||
|
@ -2071,14 +2075,14 @@ static void InitializeBuffersGPU(void)
|
||||||
// Lines - Vertex positions buffer binding and attributes enable
|
// Lines - Vertex positions buffer binding and attributes enable
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, linesBuffer[0]);
|
glBindBuffer(GL_ARRAY_BUFFER, linesBuffer[0]);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*2*MAX_LINES_BATCH, lines.vertices, GL_DYNAMIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*2*MAX_LINES_BATCH, lines.vertices, GL_DYNAMIC_DRAW);
|
||||||
glEnableVertexAttribArray(defaultVertexLoc);
|
glEnableVertexAttribArray(defaultShader.vertexLoc);
|
||||||
glVertexAttribPointer(defaultVertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
glVertexAttribPointer(defaultShader.vertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||||
|
|
||||||
// Lines - colors buffer
|
// Lines - colors buffer
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, linesBuffer[1]);
|
glBindBuffer(GL_ARRAY_BUFFER, linesBuffer[1]);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(unsigned char)*4*2*MAX_LINES_BATCH, lines.colors, GL_DYNAMIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(unsigned char)*4*2*MAX_LINES_BATCH, lines.colors, GL_DYNAMIC_DRAW);
|
||||||
glEnableVertexAttribArray(defaultColorLoc);
|
glEnableVertexAttribArray(defaultShader.colorLoc);
|
||||||
glVertexAttribPointer(defaultColorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
glVertexAttribPointer(defaultShader.colorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
||||||
|
|
||||||
if (vaoSupported) TraceLog(INFO, "[VAO ID %i] Lines VAO initialized successfully", vaoLines);
|
if (vaoSupported) TraceLog(INFO, "[VAO ID %i] Lines VAO initialized successfully", vaoLines);
|
||||||
else TraceLog(INFO, "[VBO ID %i][VBO ID %i] Lines VBOs initialized successfully", linesBuffer[0], linesBuffer[1]);
|
else TraceLog(INFO, "[VBO ID %i][VBO ID %i] Lines VBOs initialized successfully", linesBuffer[0], linesBuffer[1]);
|
||||||
|
@ -2097,13 +2101,13 @@ static void InitializeBuffersGPU(void)
|
||||||
// Enable vertex attributes
|
// Enable vertex attributes
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, trianglesBuffer[0]);
|
glBindBuffer(GL_ARRAY_BUFFER, trianglesBuffer[0]);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*3*MAX_TRIANGLES_BATCH, triangles.vertices, GL_DYNAMIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*3*MAX_TRIANGLES_BATCH, triangles.vertices, GL_DYNAMIC_DRAW);
|
||||||
glEnableVertexAttribArray(defaultVertexLoc);
|
glEnableVertexAttribArray(defaultShader.vertexLoc);
|
||||||
glVertexAttribPointer(defaultVertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
glVertexAttribPointer(defaultShader.vertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, trianglesBuffer[1]);
|
glBindBuffer(GL_ARRAY_BUFFER, trianglesBuffer[1]);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(unsigned char)*4*3*MAX_TRIANGLES_BATCH, triangles.colors, GL_DYNAMIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(unsigned char)*4*3*MAX_TRIANGLES_BATCH, triangles.colors, GL_DYNAMIC_DRAW);
|
||||||
glEnableVertexAttribArray(defaultColorLoc);
|
glEnableVertexAttribArray(defaultShader.colorLoc);
|
||||||
glVertexAttribPointer(defaultColorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
glVertexAttribPointer(defaultShader.colorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
||||||
|
|
||||||
if (vaoSupported) TraceLog(INFO, "[VAO ID %i] Triangles VAO initialized successfully", vaoTriangles);
|
if (vaoSupported) TraceLog(INFO, "[VAO ID %i] Triangles VAO initialized successfully", vaoTriangles);
|
||||||
else TraceLog(INFO, "[VBO ID %i][VBO ID %i] Triangles VBOs initialized successfully", trianglesBuffer[0], trianglesBuffer[1]);
|
else TraceLog(INFO, "[VBO ID %i][VBO ID %i] Triangles VBOs initialized successfully", trianglesBuffer[0], trianglesBuffer[1]);
|
||||||
|
@ -2122,18 +2126,18 @@ static void InitializeBuffersGPU(void)
|
||||||
// Enable vertex attributes
|
// Enable vertex attributes
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, quadsBuffer[0]);
|
glBindBuffer(GL_ARRAY_BUFFER, quadsBuffer[0]);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*4*MAX_QUADS_BATCH, quads.vertices, GL_DYNAMIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*4*MAX_QUADS_BATCH, quads.vertices, GL_DYNAMIC_DRAW);
|
||||||
glEnableVertexAttribArray(defaultVertexLoc);
|
glEnableVertexAttribArray(defaultShader.vertexLoc);
|
||||||
glVertexAttribPointer(defaultVertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
glVertexAttribPointer(defaultShader.vertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, quadsBuffer[1]);
|
glBindBuffer(GL_ARRAY_BUFFER, quadsBuffer[1]);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*4*MAX_QUADS_BATCH, quads.texcoords, GL_DYNAMIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*4*MAX_QUADS_BATCH, quads.texcoords, GL_DYNAMIC_DRAW);
|
||||||
glEnableVertexAttribArray(defaultTexcoordLoc);
|
glEnableVertexAttribArray(defaultShader.texcoordLoc);
|
||||||
glVertexAttribPointer(defaultTexcoordLoc, 2, GL_FLOAT, 0, 0, 0);
|
glVertexAttribPointer(defaultShader.texcoordLoc, 2, GL_FLOAT, 0, 0, 0);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, quadsBuffer[2]);
|
glBindBuffer(GL_ARRAY_BUFFER, quadsBuffer[2]);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(unsigned char)*4*4*MAX_QUADS_BATCH, quads.colors, GL_DYNAMIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(unsigned char)*4*4*MAX_QUADS_BATCH, quads.colors, GL_DYNAMIC_DRAW);
|
||||||
glEnableVertexAttribArray(defaultColorLoc);
|
glEnableVertexAttribArray(defaultShader.colorLoc);
|
||||||
glVertexAttribPointer(defaultColorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
glVertexAttribPointer(defaultShader.colorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
||||||
|
|
||||||
// Fill index buffer
|
// Fill index buffer
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, quadsBuffer[3]);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, quadsBuffer[3]);
|
||||||
|
|
40
src/rlgl.h
40
src/rlgl.h
|
@ -32,7 +32,7 @@
|
||||||
//#define RLGL_STANDALONE // NOTE: To use rlgl as standalone lib, just uncomment this line
|
//#define RLGL_STANDALONE // NOTE: To use rlgl as standalone lib, just uncomment this line
|
||||||
|
|
||||||
#ifndef RLGL_STANDALONE
|
#ifndef RLGL_STANDALONE
|
||||||
#include "raylib.h" // Required for typedef: Model
|
#include "raylib.h" // Required for typedef(s): Model, Shader, Texture2D
|
||||||
#include "utils.h" // Required for function TraceLog()
|
#include "utils.h" // Required for function TraceLog()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -88,8 +88,11 @@ typedef enum { RL_LINES, RL_TRIANGLES, RL_QUADS } DrawMode;
|
||||||
|
|
||||||
typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion;
|
typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion;
|
||||||
|
|
||||||
|
typedef enum { GRAYSCALE = 0, R5G6B5, R8G8B8, R5G5B5A1, R4G4B4A4, R8G8B8A8 } ColorMode;
|
||||||
|
|
||||||
#ifdef RLGL_STANDALONE
|
#ifdef RLGL_STANDALONE
|
||||||
typedef struct {
|
// VertexData type
|
||||||
|
typedef struct VertexData {
|
||||||
int vertexCount;
|
int vertexCount;
|
||||||
float *vertices; // 3 components per vertex
|
float *vertices; // 3 components per vertex
|
||||||
float *texcoords; // 2 components per vertex
|
float *texcoords; // 2 components per vertex
|
||||||
|
@ -97,11 +100,38 @@ typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion;
|
||||||
unsigned char *colors;
|
unsigned char *colors;
|
||||||
} VertexData;
|
} VertexData;
|
||||||
|
|
||||||
|
// Texture2D type
|
||||||
|
typedef struct Texture2D {
|
||||||
|
unsigned int id; // Texture id
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
} Texture2D;
|
||||||
|
|
||||||
|
// Shader type
|
||||||
|
typedef struct Shader {
|
||||||
|
unsigned int id; // Shader program id
|
||||||
|
|
||||||
|
// Variable attributes
|
||||||
|
unsigned int vertexLoc; // Vertex attribute location point (vertex shader)
|
||||||
|
unsigned int texcoordLoc; // Texcoord attribute location point (vertex shader)
|
||||||
|
unsigned int normalLoc; // Normal attribute location point (vertex shader)
|
||||||
|
unsigned int colorLoc; // Color attibute location point (vertex shader)
|
||||||
|
|
||||||
|
// Uniforms
|
||||||
|
unsigned int projectionLoc; // Projection matrix uniform location point (vertex shader)
|
||||||
|
unsigned int modelviewLoc; // ModeView matrix uniform location point (vertex shader)
|
||||||
|
unsigned int textureLoc; // Texture uniform location point (fragment shader)
|
||||||
|
unsigned int tintColorLoc; // Color uniform location point (fragment shader)
|
||||||
|
} Shader;
|
||||||
|
|
||||||
|
// 3d Model type
|
||||||
|
// NOTE: If using OpenGL 1.1, loaded in CPU (mesh); if OpenGL 3.3+ loaded in GPU (vaoId)
|
||||||
typedef struct Model {
|
typedef struct Model {
|
||||||
VertexData mesh;
|
VertexData mesh;
|
||||||
unsigned int vaoId;
|
unsigned int vaoId;
|
||||||
unsigned int vboId[4];
|
unsigned int vboId[4];
|
||||||
unsigned int textureId;
|
Texture2D texture;
|
||||||
|
Shader shader;
|
||||||
//Matrix transform;
|
//Matrix transform;
|
||||||
} Model;
|
} Model;
|
||||||
#endif
|
#endif
|
||||||
|
@ -163,9 +193,11 @@ void rlglDraw(void); // Draw VAO/VBO
|
||||||
void rlglDrawPostpro(unsigned int shaderId); // Draw with postpro shader
|
void rlglDrawPostpro(unsigned int shaderId); // Draw with postpro shader
|
||||||
void rlglInitGraphics(int offsetX, int offsetY, int width, int height); // Initialize Graphics (OpenGL stuff)
|
void rlglInitGraphics(int offsetX, int offsetY, int width, int height); // Initialize Graphics (OpenGL stuff)
|
||||||
|
|
||||||
unsigned int rlglLoadTexture(unsigned char *data, int width, int height, bool genMipmaps); // Load in GPU OpenGL texture
|
unsigned int rlglLoadTexture(unsigned char *data, int width, int height, int colorMode, bool genMipmaps); // Load in GPU OpenGL texture
|
||||||
unsigned int rlglLoadCompressedTexture(unsigned char *data, int width, int height, int mipmapCount, int format);
|
unsigned int rlglLoadCompressedTexture(unsigned char *data, int width, int height, int mipmapCount, int format);
|
||||||
|
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
unsigned int rlglLoadShader(char *vShaderStr, char *fShaderStr); // Load a shader from text data
|
unsigned int rlglLoadShader(char *vShaderStr, char *fShaderStr); // Load a shader from text data
|
||||||
|
#endif
|
||||||
|
|
||||||
Model rlglLoadModel(VertexData mesh); // Upload vertex data into GPU and provided VAO/VBO ids
|
Model rlglLoadModel(VertexData mesh); // Upload vertex data into GPU and provided VAO/VBO ids
|
||||||
void rlglDrawModel(Model model, Vector3 position, Vector3 rotation, Vector3 scale, Color color, bool wires);
|
void rlglDrawModel(Model model, Vector3 position, Vector3 rotation, Vector3 scale, Color color, bool wires);
|
||||||
|
|
|
@ -306,7 +306,7 @@ Texture2D LoadTexture(const char *fileName)
|
||||||
|
|
||||||
if (image.compFormat == 0)
|
if (image.compFormat == 0)
|
||||||
{
|
{
|
||||||
texture.id = rlglLoadTexture(image.data, image.width, image.height, false);
|
texture.id = rlglLoadTexture(image.data, image.width, image.height, R8G8B8A8, false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -352,6 +352,8 @@ Texture2D LoadTexture(const char *fileName)
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Texture2D LoadTextureEx(const char *imageData, int width, int height, int colorMode)
|
||||||
|
|
||||||
// Load a texture from image data
|
// Load a texture from image data
|
||||||
// NOTE: image is not unloaded, it must be done manually
|
// NOTE: image is not unloaded, it must be done manually
|
||||||
Texture2D LoadTextureFromImage(Image image, bool genMipmaps)
|
Texture2D LoadTextureFromImage(Image image, bool genMipmaps)
|
||||||
|
@ -380,7 +382,7 @@ Texture2D LoadTextureFromImage(Image image, bool genMipmaps)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: rlglLoadTexture() can generate mipmaps (POT image required)
|
// NOTE: rlglLoadTexture() can generate mipmaps (POT image required)
|
||||||
texture.id = rlglLoadTexture(imgData, image.width, image.height, genMipmaps);
|
texture.id = rlglLoadTexture(imgData, image.width, image.height, R8G8B8A8, genMipmaps);
|
||||||
|
|
||||||
texture.width = image.width;
|
texture.width = image.width;
|
||||||
texture.height = image.height;
|
texture.height = image.height;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue