raylib/examples/textures_rectangle.c

70 lines
2.8 KiB
C
Raw Normal View History

2013-11-24 20:30:05 +01:00
/*******************************************************************************************
*
2014-09-29 23:41:05 +02:00
* raylib [textures] example - Texture loading and drawing a part defined by a rectangle
2013-11-24 20:30:05 +01:00
*
* This example has been created using raylib 1.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
2013-11-24 20:30:05 +01:00
*
********************************************************************************************/
#include "raylib.h"
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
2013-11-24 20:30:05 +01:00
int screenWidth = 800;
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [texture] example - texture rectangle");
2014-09-29 23:41:05 +02:00
2013-12-20 12:50:43 +01:00
const char textLine1[] = "Lena image is a standard test image which has been in use since 1973.";
const char textLine2[] = "It comprises 512x512 pixels, and it is probably the most widely used";
const char textLine3[] = "test image for all sorts of image processing algorithms.";
2013-11-24 20:30:05 +01:00
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
2013-12-20 12:50:43 +01:00
Texture2D texture = LoadTexture("resources/lena.png"); // Texture loading
2014-09-29 23:41:05 +02:00
Rectangle eyesRec = { 225, 240, 155, 50 }; // Part of the texture to draw
2013-12-20 12:50:43 +01:00
Vector2 position = { 369, 241 };
//--------------------------------------------------------------------------------------
2014-09-29 23:41:05 +02:00
2013-11-24 20:30:05 +01:00
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
2013-11-24 20:30:05 +01:00
// TODO: Update your variables here
//----------------------------------------------------------------------------------
2014-09-29 23:41:05 +02:00
2013-11-24 20:30:05 +01:00
// Draw
//----------------------------------------------------------------------------------
2013-11-24 20:30:05 +01:00
BeginDrawing();
2014-09-29 23:41:05 +02:00
2013-11-24 20:30:05 +01:00
ClearBackground(RAYWHITE);
2014-09-29 23:41:05 +02:00
2013-12-20 12:50:43 +01:00
DrawText("LENA", 220, 100, 20, PINK);
2014-09-29 23:41:05 +02:00
DrawTexture(texture, screenWidth/2 - 256, 0, Fade(WHITE, 0.1f)); // Draw background image
2014-09-29 23:41:05 +02:00
2013-12-20 12:50:43 +01:00
DrawTextureRec(texture, eyesRec, position, WHITE); // Draw eyes part of image
DrawText(textLine1, 220, 140, 10, DARKGRAY);
2014-09-29 23:41:05 +02:00
DrawText(textLine2, 220, 160, 10, DARKGRAY);
DrawText(textLine3, 220, 180, 10, DARKGRAY);
2013-11-24 20:30:05 +01:00
EndDrawing();
//----------------------------------------------------------------------------------
2013-11-24 20:30:05 +01:00
}
// De-Initialization
//--------------------------------------------------------------------------------------
2013-11-24 20:30:05 +01:00
UnloadTexture(texture); // Texture unloading
2014-09-29 23:41:05 +02:00
2013-11-24 20:30:05 +01:00
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
2014-09-29 23:41:05 +02:00
2013-11-24 20:30:05 +01:00
return 0;
}