Updated example to new render to texture system

This commit is contained in:
raysan5 2016-03-30 20:19:46 +02:00
parent 66b096d978
commit 108055cd62

View file

@ -47,7 +47,11 @@ int main()
float swirlCenter[2] = { (float)screenWidth/2, (float)screenHeight/2 };
SetPostproShader(shader); // Set fullscreen postprocessing shader
// NOTE: Old postprocessing system is not flexible enough despite being very easy to use
//SetPostproShader(shader); // Set fullscreen postprocessing shader
// New postprocessing system let the user create multiple RenderTexture2D and perform multiple render passes
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
// Setup orbital camera
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
@ -79,6 +83,8 @@ int main()
ClearBackground(RAYWHITE);
BeginTextureMode(target); // Enable render to texture RenderTexture2D
Begin3dMode(camera);
DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
@ -87,6 +93,13 @@ int main()
End3dMode();
EndTextureMode(); // End drawing to texture (now we have a texture available for next passes)
SetCustomShader(shader);
// 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);
SetDefaultShader();
DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, GRAY);
DrawFPS(10, 10);
@ -100,6 +113,7 @@ int main()
UnloadShader(shader); // Unload shader
UnloadTexture(texture); // Unload texture
UnloadModel(dwarf); // Unload model
UnloadRenderTexture(target); // Unload render texture
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------