REVIEWED: rlgl_standalone usage
This commit is contained in:
parent
5325d8d2ba
commit
6f5a4a9351
@ -65,6 +65,15 @@
|
|||||||
#define RAYWHITE (Color){ 245, 245, 245, 255 } // My own White (raylib logo)
|
#define RAYWHITE (Color){ 245, 245, 245, 255 } // My own White (raylib logo)
|
||||||
#define DARKGRAY (Color){ 80, 80, 80, 255 } // Dark Gray
|
#define DARKGRAY (Color){ 80, 80, 80, 255 } // Dark Gray
|
||||||
|
|
||||||
|
// Camera type, defines a camera position/orientation in 3d space
|
||||||
|
typedef struct Camera {
|
||||||
|
Vector3 position; // Camera position
|
||||||
|
Vector3 target; // Camera target it looks-at
|
||||||
|
Vector3 up; // Camera up vector (rotation over its axis)
|
||||||
|
float fovy; // Camera field-of-view apperture in Y (degrees) in perspective, used as near plane width in orthographic
|
||||||
|
int projection; // Camera projection: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
|
||||||
|
} Camera;
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module specific Functions Declaration
|
// Module specific Functions Declaration
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
@ -170,15 +179,15 @@ int main(void)
|
|||||||
Matrix matProj = MatrixPerspective(camera.fovy*DEG2RAD, (double)screenWidth/(double)screenHeight, 0.01, 1000.0);
|
Matrix matProj = MatrixPerspective(camera.fovy*DEG2RAD, (double)screenWidth/(double)screenHeight, 0.01, 1000.0);
|
||||||
Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up);
|
Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up);
|
||||||
|
|
||||||
SetMatrixModelview(matView); // Set internal modelview matrix (default shader)
|
rlSetMatrixModelview(matView); // Set internal modelview matrix (default shader)
|
||||||
SetMatrixProjection(matProj); // Set internal projection matrix (default shader)
|
rlSetMatrixProjection(matProj); // Set internal projection matrix (default shader)
|
||||||
|
|
||||||
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
|
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
|
||||||
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, RAYWHITE);
|
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, RAYWHITE);
|
||||||
DrawGrid(10, 1.0f);
|
DrawGrid(10, 1.0f);
|
||||||
|
|
||||||
// NOTE: Internal buffers drawing (3D data)
|
// Draw internal render batch buffers (3D data)
|
||||||
rlglDraw();
|
rlDrawRenderBatchActive();
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
|
|
||||||
// Draw '2D' elements in the scene (GUI)
|
// Draw '2D' elements in the scene (GUI)
|
||||||
@ -188,8 +197,8 @@ int main(void)
|
|||||||
matProj = MatrixOrtho(0.0, screenWidth, screenHeight, 0.0, 0.0, 1.0);
|
matProj = MatrixOrtho(0.0, screenWidth, screenHeight, 0.0, 0.0, 1.0);
|
||||||
matView = MatrixIdentity();
|
matView = MatrixIdentity();
|
||||||
|
|
||||||
SetMatrixModelview(matView); // Set internal modelview matrix (default shader)
|
rlSetMatrixModelview(matView); // Set internal modelview matrix (default shader)
|
||||||
SetMatrixProjection(matProj); // Set internal projection matrix (default shader)
|
rlSetMatrixProjection(matProj); // Set internal projection matrix (default shader)
|
||||||
|
|
||||||
#else // Let rlgl generate and multiply matrix internally
|
#else // Let rlgl generate and multiply matrix internally
|
||||||
|
|
||||||
@ -201,8 +210,8 @@ int main(void)
|
|||||||
#endif
|
#endif
|
||||||
DrawRectangleV((Vector2){ 10.0f, 10.0f }, (Vector2){ 780.0f, 20.0f }, DARKGRAY);
|
DrawRectangleV((Vector2){ 10.0f, 10.0f }, (Vector2){ 780.0f, 20.0f }, DARKGRAY);
|
||||||
|
|
||||||
// NOTE: Internal buffers drawing (2D data)
|
// Draw internal render batch buffers (3D data)
|
||||||
rlglDraw();
|
rlDrawRenderBatchActive();
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
|
19
src/rlgl.h
19
src/rlgl.h
@ -3248,12 +3248,12 @@ void rlDrawMesh(Mesh mesh, Material material, Matrix transform)
|
|||||||
|
|
||||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
// Bind shader program
|
// Bind shader program
|
||||||
glUseProgram(material.shader.id);
|
rlEnableShader(material.shader.id);
|
||||||
|
|
||||||
// Matrices and other values required by shader
|
// Matrices and other values required by shader
|
||||||
//-----------------------------------------------------
|
//-----------------------------------------------------
|
||||||
// Calculate and send to shader model matrix (used by PBR shader)
|
// Calculate and send to shader model matrix
|
||||||
if (material.shader.locs[SHADER_LOC_MATRIX_MODEL] != -1) SetShaderValueMatrix(material.shader, material.shader.locs[SHADER_LOC_MATRIX_MODEL], transform);
|
if (material.shader.locs[SHADER_LOC_MATRIX_MODEL] != -1) rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_MODEL], transform);
|
||||||
|
|
||||||
// Upload to shader material.colDiffuse
|
// Upload to shader material.colDiffuse
|
||||||
if (material.shader.locs[SHADER_LOC_COLOR_DIFFUSE] != -1)
|
if (material.shader.locs[SHADER_LOC_COLOR_DIFFUSE] != -1)
|
||||||
@ -3269,8 +3269,8 @@ void rlDrawMesh(Mesh mesh, Material material, Matrix transform)
|
|||||||
(float)material.maps[MATERIAL_MAP_SPECULAR].color.b/255.0f,
|
(float)material.maps[MATERIAL_MAP_SPECULAR].color.b/255.0f,
|
||||||
(float)material.maps[MATERIAL_MAP_SPECULAR].color.a/255.0f);
|
(float)material.maps[MATERIAL_MAP_SPECULAR].color.a/255.0f);
|
||||||
|
|
||||||
if (material.shader.locs[SHADER_LOC_MATRIX_VIEW] != -1) SetShaderValueMatrix(material.shader, material.shader.locs[SHADER_LOC_MATRIX_VIEW], RLGL.State.modelview);
|
if (material.shader.locs[SHADER_LOC_MATRIX_VIEW] != -1) rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_VIEW], RLGL.State.modelview);
|
||||||
if (material.shader.locs[SHADER_LOC_MATRIX_PROJECTION] != -1) SetShaderValueMatrix(material.shader, material.shader.locs[SHADER_LOC_MATRIX_PROJECTION], RLGL.State.projection);
|
if (material.shader.locs[SHADER_LOC_MATRIX_PROJECTION] != -1) rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_PROJECTION], RLGL.State.projection);
|
||||||
|
|
||||||
// At this point the modelview matrix just contains the view matrix (camera)
|
// At this point the modelview matrix just contains the view matrix (camera)
|
||||||
// That's because BeginMode3D() sets it an no model-drawing function modifies it, all use rlPushMatrix() and rlPopMatrix()
|
// That's because BeginMode3D() sets it an no model-drawing function modifies it, all use rlPushMatrix() and rlPopMatrix()
|
||||||
@ -4036,7 +4036,8 @@ TextureCubemap rlGenTexturePrefilter(Shader shader, TextureCubemap cubemap, int
|
|||||||
|
|
||||||
// Define projection matrix and send it to shader
|
// Define projection matrix and send it to shader
|
||||||
Matrix fboProjection = MatrixPerspective(90.0*DEG2RAD, 1.0, RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR);
|
Matrix fboProjection = MatrixPerspective(90.0*DEG2RAD, 1.0, RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR);
|
||||||
SetShaderValueMatrix(shader, shader.locs[SHADER_LOC_MATRIX_PROJECTION], fboProjection);
|
rlEnableShader(shader.id);
|
||||||
|
rlSetUniformMatrix(shader.locs[SHADER_LOC_MATRIX_PROJECTION], fboProjection);
|
||||||
|
|
||||||
// Define view matrix for every side of the cubemap
|
// Define view matrix for every side of the cubemap
|
||||||
Matrix fboViews[6] = {
|
Matrix fboViews[6] = {
|
||||||
@ -4048,12 +4049,11 @@ TextureCubemap rlGenTexturePrefilter(Shader shader, TextureCubemap cubemap, int
|
|||||||
MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, 0.0f, -1.0f }, (Vector3){ 0.0f, -1.0f, 0.0f })
|
MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, 0.0f, -1.0f }, (Vector3){ 0.0f, -1.0f, 0.0f })
|
||||||
};
|
};
|
||||||
|
|
||||||
rlEnableShader(shader.id);
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap.id);
|
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap.id);
|
||||||
|
|
||||||
// TODO: Locations should be taken out of this function... too shader dependant...
|
// TODO: Locations should be taken out of this function... too shader dependant...
|
||||||
int roughnessLoc = GetShaderLocation(shader, "roughness");
|
int roughnessLoc = rlGetLocationUniform(shader.id, "roughness");
|
||||||
|
|
||||||
rlEnableFramebuffer(fbo);
|
rlEnableFramebuffer(fbo);
|
||||||
|
|
||||||
@ -4075,7 +4075,8 @@ TextureCubemap rlGenTexturePrefilter(Shader shader, TextureCubemap cubemap, int
|
|||||||
|
|
||||||
for (int i = 0; i < 6; i++)
|
for (int i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
SetShaderValueMatrix(shader, shader.locs[SHADER_LOC_MATRIX_VIEW], fboViews[i]);
|
//rlEnableShader(shader.id);
|
||||||
|
rlSetUniformMatrix(shader.locs[SHADER_LOC_MATRIX_VIEW], fboViews[i]);
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, prefilter.id, mip);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, prefilter.id, mip);
|
||||||
//rlFramebufferAttach(fbo, irradiance.id, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_CUBEMAP_POSITIVE_X + i); // TODO: Support mip levels?
|
//rlFramebufferAttach(fbo, irradiance.id, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_CUBEMAP_POSITIVE_X + i); // TODO: Support mip levels?
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user