1/*******************************************************************************************
2*
3* raylib [textures] example - Load textures from raw data
4*
5* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM)
6*
7* This example has been created using raylib 1.3 (www.raylib.com)
8* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
9*
10* Copyright (c) 2015 Ramon Santamaria (@raysan5)
11*
12********************************************************************************************/
13
14#include "raylib.h"
15
16#include <stdlib.h> // Required for: malloc() and free()
17
18int main(void)
19{
20 // Initialization
21 //--------------------------------------------------------------------------------------
22 const int screenWidth = 800;
23 const int screenHeight = 450;
24
25 InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture from raw data");
26
27 // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
28
29 // Load RAW image data (512x512, 32bit RGBA, no file header)
30 Image fudesumiRaw = LoadImageRaw("resources/fudesumi.raw", 384, 512, UNCOMPRESSED_R8G8B8A8, 0);
31 Texture2D fudesumi = LoadTextureFromImage(fudesumiRaw); // Upload CPU (RAM) image to GPU (VRAM)
32 UnloadImage(fudesumiRaw); // Unload CPU (RAM) image data
33
34 // Generate a checked texture by code
35 int width = 960;
36 int height = 480;
37
38 // Dynamic memory allocation to store pixels data (Color type)
39 Color *pixels = (Color *)malloc(width*height*sizeof(Color));
40
41 for (int y = 0; y < height; y++)
42 {
43 for (int x = 0; x < width; x++)
44 {
45 if (((x/32+y/32)/1)%2 == 0) pixels[y*width + x] = ORANGE;
46 else pixels[y*width + x] = GOLD;
47 }
48 }
49
50 // Load pixels data into an image structure and create texture
51 Image checkedIm = LoadImageEx(pixels, width, height);
52 Texture2D checked = LoadTextureFromImage(checkedIm);
53 UnloadImage(checkedIm); // Unload CPU (RAM) image data
54
55 // Dynamic memory must be freed after using it
56 free(pixels); // Unload CPU (RAM) pixels data
57 //---------------------------------------------------------------------------------------
58
59 // Main game loop
60 while (!WindowShouldClose()) // Detect window close button or ESC key
61 {
62 // Update
63 //----------------------------------------------------------------------------------
64 // TODO: Update your variables here
65 //----------------------------------------------------------------------------------
66
67 // Draw
68 //----------------------------------------------------------------------------------
69 BeginDrawing();
70
71 ClearBackground(RAYWHITE);
72
73 DrawTexture(checked, screenWidth/2 - checked.width/2, screenHeight/2 - checked.height/2, Fade(WHITE, 0.5f));
74 DrawTexture(fudesumi, 430, -30, WHITE);
75
76 DrawText("CHECKED TEXTURE ", 84, 85, 30, BROWN);
77 DrawText("GENERATED by CODE", 72, 148, 30, BROWN);
78 DrawText("and RAW IMAGE LOADING", 46, 210, 30, BROWN);
79
80 DrawText("(c) Fudesumi sprite by Eiden Marsal", 310, screenHeight - 20, 10, BROWN);
81
82 EndDrawing();
83 //----------------------------------------------------------------------------------
84 }
85
86 // De-Initialization
87 //--------------------------------------------------------------------------------------
88 UnloadTexture(fudesumi); // Texture unloading
89 UnloadTexture(checked); // Texture unloading
90
91 CloseWindow(); // Close window and OpenGL context
92 //--------------------------------------------------------------------------------------
93
94 return 0;
95}