mirror of
https://github.com/raysan5/raylib.git
synced 2025-09-07 11:58:13 +00:00
Simplified texture flip and added comments
This commit is contained in:
@@ -94,7 +94,7 @@ int main()
|
|||||||
|
|
||||||
SetCustomShader(shader);
|
SetCustomShader(shader);
|
||||||
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
|
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
|
||||||
DrawTextureRec(target.texture, (Rectangle){ 0, target.texture.height, target.texture.width, -target.texture.height }, (Vector2){ 0, 0 }, WHITE);
|
DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, -target.texture.height }, (Vector2){ 0, 0 }, WHITE);
|
||||||
SetDefaultShader();
|
SetDefaultShader();
|
||||||
|
|
||||||
DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, GRAY);
|
DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, GRAY);
|
||||||
|
@@ -82,7 +82,7 @@ int main()
|
|||||||
|
|
||||||
SetCustomShader(shader);
|
SetCustomShader(shader);
|
||||||
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
|
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
|
||||||
DrawTextureRec(target.texture, (Rectangle){ 0, target.texture.height, target.texture.width, -target.texture.height }, (Vector2){ 0, 0 }, WHITE);
|
DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, -target.texture.height }, (Vector2){ 0, 0 }, WHITE);
|
||||||
SetDefaultShader();
|
SetDefaultShader();
|
||||||
|
|
||||||
DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, DARKGRAY);
|
DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, DARKGRAY);
|
||||||
|
10
src/rlgl.c
10
src/rlgl.c
@@ -1898,6 +1898,9 @@ Model rlglLoadModel(Mesh mesh)
|
|||||||
// Create buffers for our vertex data (positions, texcoords, normals)
|
// Create buffers for our vertex data (positions, texcoords, normals)
|
||||||
glGenBuffers(3, vertexBuffer);
|
glGenBuffers(3, vertexBuffer);
|
||||||
|
|
||||||
|
// NOTE: Default shader is assigned to model, so vbo buffers are properly linked to vertex attribs
|
||||||
|
// If model shader is changed, vbo buffers must be re-assigned to new location points (previously loaded)
|
||||||
|
|
||||||
// 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);
|
||||||
@@ -2489,13 +2492,14 @@ static Shader LoadDefaultShader(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get location handlers to for shader attributes and uniforms
|
// Get location handlers to for shader attributes and uniforms
|
||||||
|
// NOTE: If any location is not found, loc point becomes -1
|
||||||
static void LoadDefaultShaderLocations(Shader *shader)
|
static void LoadDefaultShaderLocations(Shader *shader)
|
||||||
{
|
{
|
||||||
// Get handles to GLSL input attibute locations
|
// Get handles to GLSL input attibute locations
|
||||||
shader->vertexLoc = glGetAttribLocation(shader->id, "vertexPosition");
|
shader->vertexLoc = glGetAttribLocation(shader->id, "vertexPosition");
|
||||||
shader->texcoordLoc = glGetAttribLocation(shader->id, "vertexTexCoord");
|
shader->texcoordLoc = glGetAttribLocation(shader->id, "vertexTexCoord");
|
||||||
shader->normalLoc = glGetAttribLocation(shader->id, "vertexNormal");
|
shader->normalLoc = glGetAttribLocation(shader->id, "vertexNormal");
|
||||||
shader->colorLoc = glGetAttribLocation(shader->id, "vertexColor"); // -1 if not found
|
shader->colorLoc = glGetAttribLocation(shader->id, "vertexColor");
|
||||||
|
|
||||||
// Get handles to GLSL uniform locations (vertex shader)
|
// Get handles to GLSL uniform locations (vertex shader)
|
||||||
shader->mvpLoc = glGetUniformLocation(shader->id, "mvpMatrix");
|
shader->mvpLoc = glGetUniformLocation(shader->id, "mvpMatrix");
|
||||||
@@ -2503,8 +2507,8 @@ static void LoadDefaultShaderLocations(Shader *shader)
|
|||||||
// Get handles to GLSL uniform locations (fragment shader)
|
// Get handles to GLSL uniform locations (fragment shader)
|
||||||
shader->tintColorLoc = glGetUniformLocation(shader->id, "fragTintColor");
|
shader->tintColorLoc = glGetUniformLocation(shader->id, "fragTintColor");
|
||||||
shader->mapDiffuseLoc = glGetUniformLocation(shader->id, "texture0");
|
shader->mapDiffuseLoc = glGetUniformLocation(shader->id, "texture0");
|
||||||
shader->mapNormalLoc = glGetUniformLocation(shader->id, "texture1"); // -1 if not found
|
shader->mapNormalLoc = glGetUniformLocation(shader->id, "texture1");
|
||||||
shader->mapSpecularLoc = glGetUniformLocation(shader->id, "texture2"); // -1 if not found
|
shader->mapSpecularLoc = glGetUniformLocation(shader->id, "texture2");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read text file
|
// Read text file
|
||||||
|
@@ -1385,6 +1385,10 @@ void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float sc
|
|||||||
void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint)
|
void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint)
|
||||||
{
|
{
|
||||||
Rectangle destRec = { (int)position.x, (int)position.y, abs(sourceRec.width), abs(sourceRec.height) };
|
Rectangle destRec = { (int)position.x, (int)position.y, abs(sourceRec.width), abs(sourceRec.height) };
|
||||||
|
|
||||||
|
if (sourceRec.width < 0) sourceRec.x -= sourceRec.width;
|
||||||
|
if (sourceRec.height < 0) sourceRec.y -= sourceRec.height;
|
||||||
|
|
||||||
Vector2 origin = { 0, 0 };
|
Vector2 origin = { 0, 0 };
|
||||||
|
|
||||||
DrawTexturePro(texture, sourceRec, destRec, origin, 0.0f, tint);
|
DrawTexturePro(texture, sourceRec, destRec, origin, 0.0f, tint);
|
||||||
|
Reference in New Issue
Block a user