From a68818e320cb90e2bbc772f65343cb79b78770ae Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sun, 16 Mar 2014 20:59:02 +0100 Subject: [PATCH] Update to version 1.0.6 Check CHANGELOG for the list of changes in this release! --- CHANGELOG | 18 ++- release/win32-mingw/include/raylib.h | 17 ++- release/win32-mingw/lib/libraylib.a | Bin 170068 -> 174142 bytes src/core.c | 57 ++------- src/models.c | 185 ++++++++++++++++++++++----- src/raylib.h | 11 +- src/shapes.c | 16 ++- src/text.c | 59 ++++----- src/textures.c | 68 +++------- src/vector3.c | 2 +- tests/heightmap.png | Bin 0 -> 1362 bytes tests/test_billboard.c | 77 +++++++++++ tests/test_formattext.c | 62 +++++++++ tests/test_heightmap.c | 76 +++++++++++ tests/test_image_loading.c | 60 +++++++++ tests/test_mouse_wheel.c | 57 +++++++++ tests/test_random.c | 62 +++++++++ 17 files changed, 652 insertions(+), 175 deletions(-) create mode 100644 tests/heightmap.png create mode 100644 tests/test_billboard.c create mode 100644 tests/test_formattext.c create mode 100644 tests/test_heightmap.c create mode 100644 tests/test_image_loading.c create mode 100644 tests/test_mouse_wheel.c create mode 100644 tests/test_random.c diff --git a/CHANGELOG b/CHANGELOG index d07c4433..cd4274d7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,16 +1,32 @@ changelog --------- -Current Release: raylib 1.0.4 (January 2014) +Current Release: raylib 1.0.6 (March 2014) NOTE: Only versions marked as 'Release' are available on release folder, updates are only available as source. NOTE: Current Release includes all previous updates. +----------------------------------------------- +Release: raylib 1.0.6 (16 March 2014) +----------------------------------------------- +[core] Removed unused lighting-system code +[core] Removed SetPerspective() function, calculated directly +[core] Unload and reload default font on fullscreen toggle +[core] Corrected bug gamepad buttons checking if no gamepad available +[texture] DrawTextureV() - Added, to draw using Vector2 for position +[texture] LoadTexture() - Redesigned, now uses LoadImage() + CreateTexture() +[text] FormatText() - Corrected memory leak bug +[models] Added Matrix struct and related functions +[models] DrawBillboard() - Reviewed, now it works! +[models] DrawBillboardRec() - Reviewed, now it works! +[tests] Added folder with multiple tests for new functions + ----------------------------------------------- Update: raylib 1.0.5 (28 January 2014) ----------------------------------------------- [audio] LoadSound() - Corrected a bug, WAV file was not closed! [core] GetMouseWheelMove() - Added, check mouse wheel Y movement +[texture] CreateTexture2D() renamed to CreateTexture() [models] LoadHeightmap() - Added, Heightmap can be loaded as a Model [tool] rREM updated, now supports (partially) drag and drop of files diff --git a/release/win32-mingw/include/raylib.h b/release/win32-mingw/include/raylib.h index dff65ae6..fd66819c 100644 --- a/release/win32-mingw/include/raylib.h +++ b/release/win32-mingw/include/raylib.h @@ -1,6 +1,6 @@ /********************************************************************************************* * -* raylib 1.0.4 (www.raylib.com) +* raylib 1.0.6 (www.raylib.com) * * A simple and easy-to-use library to learn videogames programming * @@ -65,6 +65,7 @@ #define KEY_SPACE 32 #define KEY_ESCAPE 256 #define KEY_ENTER 257 +#define KEY_BACKSPACE 259 #define KEY_RIGHT 262 #define KEY_LEFT 263 #define KEY_DOWN 264 @@ -278,6 +279,7 @@ bool IsMouseButtonUp(int button); // Detect if a mouse but int GetMouseX(); // Returns mouse position X int GetMouseY(); // Returns mouse position Y Vector2 GetMousePosition(); // Returns mouse position XY +int GetMouseWheelMove(); // Returns mouse wheel movement Y bool IsGamepadAvailable(int gamepad); // Detect if a gamepad is available Vector2 GetGamepadMovement(int gamepad); // Return axis movement vector for a gamepad @@ -323,11 +325,12 @@ Image LoadImage(const char *fileName); Image LoadImageFromRES(const char *rresName, int resId); // Load an image from rRES file (raylib Resource) Texture2D LoadTexture(const char *fileName); // Load an image as texture into GPU memory Texture2D LoadTextureFromRES(const char *rresName, int resId); // Load an image as texture from rRES file (raylib Resource) -Texture2D CreateTexture2D(Image image); // Create a Texture2D from Image data +Texture2D CreateTexture(Image image); // Create a Texture2D from Image data void UnloadImage(Image image); // Unload image from CPU memory (RAM) void UnloadTexture(Texture2D texture); // Unload texture from GPU memory void DrawTexture(Texture2D texture, int posX, int posY, Color tint); // Draw a Texture2D +void DrawTextureV(Texture2D texture, Vector2 position, Color tint); // Draw a Texture2D with position defined as Vector2 void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, // Draw a part of a texture defined by a rectangle with 'pro' parameters @@ -370,17 +373,13 @@ void DrawGizmo(Vector3 position, bool orbits); //------------------------------------------------------------------------------------ Model LoadModel(const char *fileName); // Load a 3d model (.OBJ) //Model LoadModelFromRES(const char *rresName, int resId); // TODO: Load a 3d model from rRES file (raylib Resource) +Model LoadHeightmap(Image heightmap, float maxHeight); // Load a heightmap image as a 3d model void UnloadModel(Model model); // Unload 3d model from memory void DrawModel(Model model, Vector3 position, float scale, Color color); // Draw a model void DrawModelEx(Model model, Texture2D texture, Vector3 position, float scale, Color tint); // Draw a textured model void DrawModelWires(Model model, Vector3 position, float scale, Color color); // Draw a model wires - -// NOTE: The following functions work but are incomplete or require some revision -// DrawHeightmap is extremely inefficient and can impact performance up to 60% -void DrawBillboard(Camera camera, Texture2D texture, Vector3 basePos, float size, Color tint); // REVIEW: Draw a billboard (raylib 1.x) -void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 basePos, float size, Color tint); // REVIEW: Draw a billboard (raylib 1.x) -void DrawHeightmap(Image heightmap, Vector3 centerPos, Vector3 scale, Color color); // REVIEW: Draw heightmap using image map (raylib 1.x) -void DrawHeightmapEx(Image heightmap, Texture2D texture, Vector3 centerPos, Vector3 scale, Color tint); // REVIEW: Draw textured heightmap (raylib 1.x) +void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint); // Draw a billboard texture +void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 center, float size, Color tint); // Draw a billboard texture defined by sourceRec //------------------------------------------------------------------------------------ // Audio Loading and Playing Functions (Module: audio) diff --git a/release/win32-mingw/lib/libraylib.a b/release/win32-mingw/lib/libraylib.a index e0a1dd4dc7f8f00368ca17231d03865504064a3f..9df0a332bfb7edeb846fb8e74157754dbe83ac9d 100644 GIT binary patch delta 25498 zcmeI5dwfjS`v3QyOhyuk1cOL|kpw|R5F`X~*~GQlin^siMNzjVq1s~8NNbF!+S;LC zT3Wrh6g^QvwW72xb$UX5TdB)QRZl5B)uOc3`hC`VW^^~-Y*oJ<+NN|h}Q55B6MG1TE|MsK* zUj*!PSyBGtNB`3aADW~n|H-E~QBnT*qyHHvKOc4W3(9}=*|b?vfAgc?$?*HSrO_$n z4?oRA70Vxex>j|_Oj0cW*{9@$<#n}YpWK3h(`Mx7-ZvpPck;k#GjmJkS_>>;J@azM z6yy%comDU+FV~2u)6ZZBkM@c9aLe=#T+wAo{wZ zL?kH6GUMn&^=ii073CC^9nsRDgc(Pd)U#Rfl^JV{sF7fsj-NN}#-+^IngeW# zGP#bTbZScet&O*9EU#90DdB)Mexflvd`-Rf;fmt4#-A7Vwc_hQuXw9H+=z&9)P1MM zZ`fuVZ6YFLUkOtbndWqZ2qcnNI44pmsP57tMZEUL=7@UgA>&BI7wQ+r)|z!J=N03< znmg@PgPz||U8XHrR4Y{ts#Oiy?K^*@6m!q zX2TdGuTE!FX>*U9``i6WU5ulo{0v=h)R5f#-Jw zl;kwnt(LTCq*{y`u|L;82!Bx>v6Ev_%3|%f*jc?V8L@Fmp~9N+viLr<&&ZCO;U3&w zjWm|(@kUa7uNE=zUx3dNeEK05rF)H_B1@03z<}QB`=M5=u&=}CglcSxj|$!oybibd z#@+Mmbqe-%|DgMU?xr7xNoAJBnAbdNU<7=MEQ*3&>J53fa8#6dNXf824|`bEEPE9O z1X$I5G9G+H*27?b%^2AvI&c=Kt?_u1=-?Hgjfm6L*sI%P+8}{h2qeI$s2qgD1sr5i z!a)!7br4Z+z##zr@*Xf(*fK~KPuL?-vMkuURJA`!r5E;8*q6cHu&R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hV`%*CeAw3+sqFZq|gZ46=0^#U`b{$0B z6o5mT3KI>Y!b}HIQDs(9DurxEqFknDn97(ORgCigU7;jBm?kr=VcO4hiAl4#)7qKj zf7V1%xO0VM_Z?PIw&pms${AI`8`8uR}EUi%wV diff --git a/src/core.c b/src/core.c index 77ba5d7b..bd373c7c 100644 --- a/src/core.c +++ b/src/core.c @@ -33,7 +33,7 @@ #include // Standard input / output lib #include // Declares malloc() and free() for memory management, rand() #include // Useful to initialize random seed -#include // Math related functions, tan() on SetPerspective +#include // Math related functions, tan() used to set perspective #include "vector3.h" // Basic Vector3 functions #include "utils.h" // WritePNG() function @@ -96,7 +96,6 @@ static void ScrollCallback(GLFWwindow* window, double xoffset, double yoffset); static void CursorEnterCallback(GLFWwindow* window, int enter); // GLFW3 Cursor Enter Callback, cursor enters client area static void WindowSizeCallback(GLFWwindow* window, int width, int height); // GLFW3 WindowSize Callback, runs when window is resized static void CameraLookAt(Vector3 position, Vector3 target, Vector3 up); // Setup camera view (updates MODELVIEW matrix) -static void SetPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar); // Setup view projection (updates PROJECTION matrix) static void TakeScreenshot(); // Takes a bitmap (BMP) screenshot and saves it in the same folder as executable //---------------------------------------------------------------------------------- @@ -147,14 +146,7 @@ void InitWindowEx(int width, int height, const char* title, bool resizable, cons LoadDefaultFont(); - if (cursorImage != NULL) - { - // Load image as texture - cursor = LoadTexture(cursorImage); - - glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); - customCursor = true; - } + if (cursorImage != NULL) SetCustomCursor(cursorImage); srand(time(NULL)); // Initialize random seed } @@ -199,6 +191,8 @@ void ToggleFullscreen() { fullscreen = !fullscreen; // Toggle fullscreen flag + UnloadDefaultFont(); + glfwDestroyWindow(window); // Destroy the current window (we will recreate it!) // TODO: WARNING! All loaded resources are lost, we loose Context! @@ -217,6 +211,8 @@ void ToggleFullscreen() glfwSetKeyCallback(window, KeyCallback); InitGraphicsDevice(); + + LoadDefaultFont(); } } @@ -275,15 +271,18 @@ void EndDrawing() // Initializes 3D mode for drawing (Camera setup) void Begin3dMode(Camera camera) { - //glEnable(GL_LIGHTING); // TODO: Setup proper lighting system (raylib 1.x) - glMatrixMode(GL_PROJECTION); // Switch to projection matrix glPushMatrix(); // Save previous matrix, which contains the settings for the 2d ortho projection glLoadIdentity(); // Reset current matrix (PROJECTION) - SetPerspective(45.0f, (GLfloat)windowWidth/(GLfloat)windowHeight, 0.1f, 100.0f); // Setup perspective projection + // Setup perspective projection + float aspect = (GLfloat)windowWidth/(GLfloat)windowHeight; + double top = 0.1f*tan(45.0f*PI / 360.0); + double right = top*aspect; + glFrustum(-right, right, -top, top, 0.1f, 100.0f); + glMatrixMode(GL_MODELVIEW); // Switch back to modelview matrix glLoadIdentity(); // Reset current matrix (MODELVIEW) @@ -300,8 +299,6 @@ void End3dMode() glLoadIdentity(); // Reset current matrix (MODELVIEW) glTranslatef(0.375, 0.375, 0); // HACK to ensure pixel-perfect drawing on OpenGL (after exiting 3D mode) - - //glDisable(GL_LIGHTING); // TODO: Setup proper lighting system (raylib 1.x) } // Set target FPS for the game @@ -570,7 +567,7 @@ bool IsGamepadButtonDown(int gamepad, int button) buttons = glfwGetJoystickButtons(gamepad, &buttonsCount); - if (buttons[button] == GLFW_PRESS) + if ((buttons != NULL) && (buttons[button] == GLFW_PRESS)) { return true; } @@ -601,7 +598,7 @@ bool IsGamepadButtonUp(int gamepad, int button) buttons = glfwGetJoystickButtons(gamepad, &buttonsCount); - if (buttons[button] == GLFW_RELEASE) + if ((buttons != NULL) && (buttons[button] == GLFW_RELEASE)) { return true; } @@ -685,19 +682,6 @@ static void InitGraphicsDevice() glMatrixMode(GL_MODELVIEW); // Switch back to MODELVIEW matrix glLoadIdentity(); // Reset current matrix (MODELVIEW) - // TODO: Create an efficient Lighting System with proper functions (raylib 1.x) -/* - glEnable(GL_COLOR_MATERIAL); // Enable materials, causes some glMaterial atributes to track the current color (glColor)... - glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); // Material types and where to apply them - // NOTE: ONLY works with lighting; defines how light interacts with material - - glLightfv(GL_LIGHT1, GL_AMBIENT, lightAmbient); // Define ambient light color property - glLightfv(GL_LIGHT1, GL_DIFFUSE, lightDiffuse); // Define diffuse light color property - glLightfv(GL_LIGHT1, GL_POSITION, lightPosition); // Define light position - - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT1); // Enable light one (8 lights available at the same time) -*/ // TODO: Review all shapes/models are drawn CCW and enable backface culling //glEnable(GL_CULL_FACE); // Enable backface culling (Disabled by default) @@ -746,19 +730,6 @@ static void CameraLookAt(Vector3 position, Vector3 target, Vector3 up) glTranslatef(-position.x, -position.y, -position.z); // Translate eye to position } -// Setup view projection (updates PROJECTION matrix) -static void SetPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar) -{ - double xmin, xmax, ymin, ymax; - - ymax = zNear * tan(fovy * PI / 360.0); - ymin = -ymax; - xmin = ymin * aspect; - xmax = ymax * aspect; - - glFrustum(xmin, xmax, ymin, ymax, zNear, zFar); -} - // Takes a bitmap (BMP) screenshot and saves it in the same folder as executable static void TakeScreenshot() { diff --git a/src/models.c b/src/models.c index 9edfb142..e21ff894 100644 --- a/src/models.c +++ b/src/models.c @@ -39,7 +39,14 @@ //---------------------------------------------------------------------------------- // Types and Structures Definition //---------------------------------------------------------------------------------- -// ... + +// Matrix type (OpenGL style 4x4 - right handed) +typedef struct Matrix { + float m0, m4, m8, m12; + float m1, m5, m9, m13; + float m2, m6, m10, m14; + float m3, m7, m11, m15; +} Matrix; //---------------------------------------------------------------------------------- // Global Variables Definition @@ -50,13 +57,15 @@ // Module specific Functions Declaration //---------------------------------------------------------------------------------- static float GetHeightValue(Color pixel); +static void MatrixTranspose(Matrix *mat); +static Matrix MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up); //---------------------------------------------------------------------------------- // Module Functions Definition //---------------------------------------------------------------------------------- // Draw cube -// NOTE: Cube position is de center position +// NOTE: Cube position is the center position void DrawCube(Vector3 position, float width, float height, float lenght, Color color) { glPushMatrix(); @@ -664,7 +673,7 @@ Model LoadHeightmap(Image heightmap, float maxHeight) Model model; int mapX = heightmap.width; - int mapZ = heightmap.height; + int mapZ = heightmap.height; // NOTE: One vertex per pixel // TODO: Consider resolution when generating model data? @@ -681,11 +690,11 @@ Model LoadHeightmap(Image heightmap, float maxHeight) float scaleFactor = maxHeight/255; // TODO: Review scaleFactor calculation - for(int z = 0; z < mapZ-1; z++) - { - for(int x = 0; x < mapX-1; x++) - { - // Fill vertices array with data + for(int z = 0; z < mapZ-1; z++) + { + for(int x = 0; x < mapX-1; x++) + { + // Fill vertices array with data //---------------------------------------------------------- // one triangle - 3 vertex @@ -738,8 +747,8 @@ Model LoadHeightmap(Image heightmap, float maxHeight) vCounter += 6; trisCounter += 2; - } - } + } + } return model; } @@ -805,47 +814,165 @@ void DrawModelWires(Model model, Vector3 position, float scale, Color color) } // Draw a billboard -void DrawBillboard(Camera camera, Texture2D texture, Vector3 basePos, float size, Color tint) +void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint) { - // NOTE: Billboard size will represent the width, height maintains aspect ratio - Vector3 centerPos = { basePos.x, basePos.y + size * (float)texture.height/(float)texture.width/2, basePos.z }; + // NOTE: Billboard size will maintain texture aspect ratio, size will be billboard width Vector2 sizeRatio = { size, size * (float)texture.height/texture.width }; - Vector3 rotation = { 90, 0, 0 }; - // TODO: Calculate Y rotation to face always camera (use matrix) - // OPTION: Lock Y-axis + Matrix viewMatrix = MatrixLookAt(camera.position, camera.target, camera.up); + MatrixTranspose(&viewMatrix); + + Vector3 right = { viewMatrix.m0, viewMatrix.m4, viewMatrix.m8 }; + Vector3 up = { viewMatrix.m1, viewMatrix.m5, viewMatrix.m9 }; +/* + d-------c + | | + | * | + | | + a-------b +*/ + VectorScale(&right, sizeRatio.x/2); + VectorScale(&up, sizeRatio.y/2); + + Vector3 p1 = VectorAdd(right, up); + Vector3 p2 = VectorSubtract(right, up); + Vector3 a = VectorSubtract(center, p2); + Vector3 b = VectorAdd(center, p1); + Vector3 c = VectorAdd(center, p2); + Vector3 d = VectorSubtract(center, p1); + glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture.glId); - - DrawPlane(centerPos, sizeRatio, rotation, tint); // TODO: Review this function... + + glBegin(GL_QUADS); + glColor4ub(tint.r, tint.g, tint.b, tint.a); + glNormal3f(0.0f, 1.0f, 0.0f); + glTexCoord2f(0.0f, 0.0f); glVertex3f(a.x, a.y, a.z); + glTexCoord2f(1.0f, 0.0f); glVertex3f(b.x, b.y, b.z); + glTexCoord2f(1.0f, 1.0f); glVertex3f(c.x, c.y, c.z); + glTexCoord2f(0.0f, 1.0f); glVertex3f(d.x, d.y, d.z); + glEnd(); glDisable(GL_TEXTURE_2D); } // Draw a billboard (part of a texture defined by a rectangle) -void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 basePos, float size, Color tint) +void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 center, float size, Color tint) { - // NOTE: Billboard size will represent the width, height maintains aspect ratio - //Vector3 centerPos = { basePos.x, basePos.y + size * (float)texture.height/(float)texture.width/2, basePos.z }; - //Vector2 sizeRatio = { size, size * (float)texture.height/texture.width }; - //Vector3 rotation = { 90, 0, 0 }; - - // TODO: Calculate Y rotation to face always camera (use matrix) - // OPTION: Lock Y-axis + // NOTE: Billboard size will maintain sourceRec aspect ratio, size will represent billboard width + Vector2 sizeRatio = { size, size * (float)sourceRec.height/sourceRec.width }; - glEnable(GL_TEXTURE_2D); + Matrix viewMatrix = MatrixLookAt(camera.position, camera.target, camera.up); + MatrixTranspose(&viewMatrix); + + Vector3 right = { viewMatrix.m0, viewMatrix.m4, viewMatrix.m8 }; + Vector3 up = { viewMatrix.m1, viewMatrix.m5, viewMatrix.m9 }; +/* + d-------c + | | + | * | + | | + a-------b +*/ + VectorScale(&right, sizeRatio.x/2); + VectorScale(&up, sizeRatio.y/2); + + Vector3 p1 = VectorAdd(right, up); + Vector3 p2 = VectorSubtract(right, up); + + Vector3 a = VectorSubtract(center, p2); + Vector3 b = VectorAdd(center, p1); + Vector3 c = VectorAdd(center, p2); + Vector3 d = VectorSubtract(center, p1); + + glEnable(GL_TEXTURE_2D); // Enable textures usage glBindTexture(GL_TEXTURE_2D, texture.glId); - // TODO: DrawPlane with correct textcoords for source rec. + glBegin(GL_QUADS); + glColor4ub(tint.r, tint.g, tint.b, tint.a); + + // Bottom-left corner for texture and quad + glTexCoord2f((float)sourceRec.x / texture.width, (float)sourceRec.y / texture.height); + glVertex3f(a.x, a.y, a.z); + + // Bottom-right corner for texture and quad + glTexCoord2f((float)(sourceRec.x + sourceRec.width) / texture.width, (float)sourceRec.y / texture.height); + glVertex3f(b.x, b.y, b.z); + + // Top-right corner for texture and quad + glTexCoord2f((float)(sourceRec.x + sourceRec.width) / texture.width, (float)(sourceRec.y + sourceRec.height) / texture.height); + glVertex3f(c.x, c.y, c.z); + + // Top-left corner for texture and quad + glTexCoord2f((float)sourceRec.x / texture.width, (float)(sourceRec.y + sourceRec.height) / texture.height); + glVertex3f(d.x, d.y, d.z); + glEnd(); - glDisable(GL_TEXTURE_2D); + glDisable(GL_TEXTURE_2D); // Disable textures usage } // Get current vertex y altitude (proportional to pixel colors in grayscale) static float GetHeightValue(Color pixel) { return (((float)pixel.r + (float)pixel.g + (float)pixel.b)/3); +} + +// Returns camera look-at matrix (view matrix) +static Matrix MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up) +{ + Matrix result; + + Vector3 z = VectorSubtract(eye, target); + VectorNormalize(&z); + Vector3 x = VectorCrossProduct(up, z); + VectorNormalize(&x); + Vector3 y = VectorCrossProduct(z, x); + VectorNormalize(&y); + + result.m0 = x.x; + result.m1 = x.y; + result.m2 = x.z; + result.m3 = -((x.x * eye.x) + (x.y * eye.y) + (x.z * eye.z)); + result.m4 = y.x; + result.m5 = y.y; + result.m6 = y.z; + result.m7 = -((y.x * eye.x) + (y.y * eye.y) + (y.z * eye.z)); + result.m8 = z.x; + result.m9 = z.y; + result.m10 = z.z; + result.m11 = -((z.x * eye.x) + (z.y * eye.y) + (z.z * eye.z)); + result.m12 = 0; + result.m13 = 0; + result.m14 = 0; + result.m15 = 1; + + return result; +} + +// Transposes provided matrix +static void MatrixTranspose(Matrix *mat) +{ + Matrix temp; + + temp.m0 = mat->m0; + temp.m1 = mat->m4; + temp.m2 = mat->m8; + temp.m3 = mat->m12; + temp.m4 = mat->m1; + temp.m5 = mat->m5; + temp.m6 = mat->m9; + temp.m7 = mat->m13; + temp.m8 = mat->m2; + temp.m9 = mat->m6; + temp.m10 = mat->m10; + temp.m11 = mat->m14; + temp.m12 = mat->m3; + temp.m13 = mat->m7; + temp.m14 = mat->m11; + temp.m15 = mat->m15; + + *mat = temp; } \ No newline at end of file diff --git a/src/raylib.h b/src/raylib.h index 867b7218..fd66819c 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1,6 +1,6 @@ /********************************************************************************************* * -* raylib 1.0.4 (www.raylib.com) +* raylib 1.0.6 (www.raylib.com) * * A simple and easy-to-use library to learn videogames programming * @@ -325,11 +325,12 @@ Image LoadImage(const char *fileName); Image LoadImageFromRES(const char *rresName, int resId); // Load an image from rRES file (raylib Resource) Texture2D LoadTexture(const char *fileName); // Load an image as texture into GPU memory Texture2D LoadTextureFromRES(const char *rresName, int resId); // Load an image as texture from rRES file (raylib Resource) -Texture2D CreateTexture(Image image); // Create a Texture2D from Image data +Texture2D CreateTexture(Image image); // Create a Texture2D from Image data void UnloadImage(Image image); // Unload image from CPU memory (RAM) void UnloadTexture(Texture2D texture); // Unload texture from GPU memory void DrawTexture(Texture2D texture, int posX, int posY, Color tint); // Draw a Texture2D +void DrawTextureV(Texture2D texture, Vector2 position, Color tint); // Draw a Texture2D with position defined as Vector2 void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, // Draw a part of a texture defined by a rectangle with 'pro' parameters @@ -377,10 +378,8 @@ void UnloadModel(Model model); void DrawModel(Model model, Vector3 position, float scale, Color color); // Draw a model void DrawModelEx(Model model, Texture2D texture, Vector3 position, float scale, Color tint); // Draw a textured model void DrawModelWires(Model model, Vector3 position, float scale, Color color); // Draw a model wires - -// NOTE: The following functions work but are incomplete or require some revision -void DrawBillboard(Camera camera, Texture2D texture, Vector3 basePos, float size, Color tint); // REVIEW: Draw a billboard (raylib 1.x) -void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 basePos, float size, Color tint); // REVIEW: Draw a billboard (raylib 1.x) +void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint); // Draw a billboard texture +void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 center, float size, Color tint); // Draw a billboard texture defined by sourceRec //------------------------------------------------------------------------------------ // Audio Loading and Playing Functions (Module: audio) diff --git a/src/shapes.c b/src/shapes.c index b033cde9..07a73cad 100644 --- a/src/shapes.c +++ b/src/shapes.c @@ -61,8 +61,16 @@ void DrawPixel(int posX, int posY, Color color) glColor4ub(color.r, color.g, color.b, color.a); glVertex2i(posX, posY); glEnd(); - - // NOTE: Alternative method to draw a pixel (point) + + // NOTE1: Alternative method to draw a pixel (GL_LINES) +/* + glBegin(GL_LINES); + glColor4ub(color.r, color.g, color.b, color.a); + glVertex2i(posX, posY); + glVertex2i(posX+1, posY+1); + glEnd(); +*/ + // NOTE2: Alternative method to draw a pixel (glPoint()) /* glEnable(GL_POINT_SMOOTH); glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); // Deprecated on OGL 3.0 @@ -426,7 +434,7 @@ Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2) if (rec1.x <= rec2.x) { if (rec1.y <= rec2.y) - { + { retRec.x = rec2.x; retRec.y = rec2.y; retRec.width = rec1.width - dxx; @@ -443,7 +451,7 @@ Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2) else { if (rec1.y <= rec2.y) - { + { retRec.x = rec1.x; retRec.y = rec2.y; retRec.width = rec2.width - dxx; diff --git a/src/text.c b/src/text.c index f1070a03..492329c5 100644 --- a/src/text.c +++ b/src/text.c @@ -8,7 +8,7 @@ * stb_image - Multiple formats image loading (JPEG, PNG, BMP, TGA, PSD, GIF, HDR, PIC) * * Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com) -* +* * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. * @@ -37,8 +37,9 @@ //---------------------------------------------------------------------------------- // Defines and Macros //---------------------------------------------------------------------------------- -#define FIRST_CHAR 32 -#define MAX_FONTCHARS 128 +#define FONT_FIRST_CHAR 32 +#define MAX_FONTCHARS 128 +#define MAX_FORMATTEXT_LENGTH 50 #define BIT_CHECK(a,b) ((a) & (1<<(b))) @@ -125,7 +126,7 @@ extern void LoadDefaultFont() for (int i = 0; i < defaultFont.numChars; i++) { - defaultFont.charSet[i].value = FIRST_CHAR + i; + defaultFont.charSet[i].value = FONT_FIRST_CHAR + i; // First char is 32 defaultFont.charSet[i].x = currentPosX; defaultFont.charSet[i].y = charsDivisor + currentLine * (charsHeight + charsDivisor); defaultFont.charSet[i].w = charsWidth[i]; @@ -329,31 +330,26 @@ void DrawTextEx(SpriteFont spriteFont, const char* text, Vector2 position, int f if (fontSize <= spriteFont.charSet[0].h) scaleFactor = 1.0f; else scaleFactor = (float)fontSize / spriteFont.charSet[0].h; - glDisable(GL_LIGHTING); // When drawing text, disable LIGHTING glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, spriteFont.texture.glId); - glPushMatrix(); - - // Optimized to use one draw call per string - glBegin(GL_QUADS); - for(int i = 0; i < length; i++) - { - c = spriteFont.charSet[(int)text[i] - FIRST_CHAR]; - - glColor4ub(tint.r, tint.g, tint.b, tint.a); - glNormal3f(0.0f, 0.0f, 1.0f); // Normal Pointing Towards Viewer - glTexCoord2f((float)c.x / spriteFont.texture.width, (float)c.y / spriteFont.texture.height); glVertex2f(positionX, position.y); - glTexCoord2f((float)c.x / spriteFont.texture.width, (float)(c.y + c.h) / spriteFont.texture.height); glVertex2f(positionX, position.y + (c.h) * scaleFactor); - glTexCoord2f((float)(c.x + c.w) / spriteFont.texture.width, (float)(c.y + c.h) / spriteFont.texture.height); glVertex2f(positionX + (c.w) * scaleFactor, position.y + (c.h) * scaleFactor); - glTexCoord2f((float)(c.x + c.w) / spriteFont.texture.width, (float)c.y / spriteFont.texture.height); glVertex2f(positionX + (c.w) * scaleFactor, position.y); - - positionX += ((spriteFont.charSet[(int)text[i] - FIRST_CHAR].w) * scaleFactor + spacing); - } - glEnd(); - - glPopMatrix(); + // Optimized to use one draw call per string + glBegin(GL_QUADS); + for(int i = 0; i < length; i++) + { + c = spriteFont.charSet[(int)text[i] - FONT_FIRST_CHAR]; + + glColor4ub(tint.r, tint.g, tint.b, tint.a); + glNormal3f(0.0f, 0.0f, 1.0f); // Normal Pointing Towards Viewer + glTexCoord2f((float)c.x / spriteFont.texture.width, (float)c.y / spriteFont.texture.height); glVertex2f(positionX, position.y); + glTexCoord2f((float)c.x / spriteFont.texture.width, (float)(c.y + c.h) / spriteFont.texture.height); glVertex2f(positionX, position.y + (c.h) * scaleFactor); + glTexCoord2f((float)(c.x + c.w) / spriteFont.texture.width, (float)(c.y + c.h) / spriteFont.texture.height); glVertex2f(positionX + (c.w) * scaleFactor, position.y + (c.h) * scaleFactor); + glTexCoord2f((float)(c.x + c.w) / spriteFont.texture.width, (float)c.y / spriteFont.texture.height); glVertex2f(positionX + (c.w) * scaleFactor, position.y); + + positionX += ((spriteFont.charSet[(int)text[i] - FONT_FIRST_CHAR].w) * scaleFactor + spacing); + } + glEnd(); glDisable(GL_TEXTURE_2D); } @@ -361,16 +357,13 @@ void DrawTextEx(SpriteFont spriteFont, const char* text, Vector2 position, int f // Formatting of text with variables to 'embed' const char *FormatText(const char *text, ...) { - int length = strlen(text); - char *buffer = malloc(length + 20); // We add 20 extra characters, should be enough... :P - + static char buffer[MAX_FORMATTEXT_LENGTH]; + va_list args; va_start(args, text); vsprintf(buffer, text, args); // NOTE: We use vsprintf() defined in va_end(args); - - //strcat(buffer, "\0"); // We add a end-of-string mark at the end (not needed) - + return buffer; } @@ -393,7 +386,7 @@ Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, int fontSize, int for (int i = 0; i < len; i++) { - textWidth += spriteFont.charSet[(int)text[i] - FIRST_CHAR].w; + textWidth += spriteFont.charSet[(int)text[i] - FONT_FIRST_CHAR].w; } if (fontSize <= spriteFont.charSet[0].h) scaleFactor = 1.0f; @@ -491,7 +484,7 @@ static int ParseImageData(Color *imgDataPixel, int imgWidth, int imgHeight, Char while((xPosToRead < imgWidth) && !PixelIsMagenta((imgDataPixel[(lineSpacing + (charHeight+lineSpacing)*lineToRead)*imgWidth + xPosToRead]))) { - tempCharSet[index].value = FIRST_CHAR + index; + tempCharSet[index].value = FONT_FIRST_CHAR + index; tempCharSet[index].x = xPosToRead; tempCharSet[index].y = lineSpacing + lineToRead * (charHeight + lineSpacing); tempCharSet[index].h = charHeight; diff --git a/src/textures.c b/src/textures.c index c0832477..ca0492c4 100644 --- a/src/textures.c +++ b/src/textures.c @@ -218,37 +218,11 @@ Image LoadImageFromRES(const char *rresName, int resId) Texture2D LoadTexture(const char *fileName) { Texture2D texture; - - int imgWidth; - int imgHeight; - int imgBpp; + Image image; - // NOTE: Using stb_image to load images (Supports: BMP, TGA, PNG, JPG, ...) - // Force loading to 4 components (RGBA) - byte *imgData = stbi_load(fileName, &imgWidth, &imgHeight, &imgBpp, 4); - - // Convert loaded data to OpenGL texture - //---------------------------------------- - GLuint id; - glGenTextures(1, &id); // Generate Pointer to the Texture - - glBindTexture(GL_TEXTURE_2D, id); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // Set texture to repead on x-axis - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // Set texture to repead on y-axis - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // Filter for pixel-perfect drawing, alternative: GL_LINEAR - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Filter for pixel-perfect drawing, alternative: GL_LINEAR - - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, imgWidth, imgHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, imgData); - - // NOTE: Not using mipmappings (texture for 2D drawing) - // At this point we have the image converted to texture and uploaded to GPU - - stbi_image_free(imgData); // Now we can free loaded data from RAM memory - - texture.glId = id; - texture.width = imgWidth; - texture.height = imgHeight; + image = LoadImage(fileName); + texture = CreateTexture(image); + UnloadImage(image); return texture; } @@ -264,23 +238,6 @@ Texture2D LoadTextureFromRES(const char *rresName, int resId) return texture; } -// Load an image as texture (and convert to POT with mipmaps) -Texture2D LoadTextureEx(const char *fileName, bool createPOT, bool mipmaps) -{ - Texture2D texture; - - // TODO: Load and image and convert to Power-Of-Two - // NOTE: Conversion could be done just adding extra space to image or by scaling image - // NOTE: If scaling image, be careful with scaling algorithm (aproximation, bilinear, bicubic...) - - // TODO: Generate all required mipmap levels from image and convert to testure (not that easy) - // NOTE: If using OpenGL 1.1, the only option is doing mipmap generation on CPU side (i.e. gluBuild2DMipmaps) - // NOTE: raylib tries to minimize external dependencies so, we are not using GLU - // NOTE: Re-implement some function similar to gluBuild2DMipmaps (not that easy...) - - return texture; -} - // Create a Texture2D from Image data // NOTE: Image is not unloaded, it should be done manually... Texture2D CreateTexture(Image image) @@ -294,11 +251,18 @@ Texture2D CreateTexture(Image image) glBindTexture(GL_TEXTURE_2D, id); + // NOTE: glTexParameteri does NOT affect texture uploading, just the way it's used! glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // Set texture to repead on x-axis glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // Set texture to repead on y-axis - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // Filter for pixel-perfect drawing, alternative: GL_LINEAR - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Filter for pixel-perfect drawing, alternative: GL_LINEAR + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Filter for pixel-perfect drawing, alternative: GL_LINEAR + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // Filter for pixel-perfect drawing, alternative: GL_LINEAR + // Trilinear filtering + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // Activate use of mipmaps (must be available) + //glGenerateMipmap(GL_TEXTURE_2D); // OpenGL 3.3! + + // Upload texture to GPU glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image.width, image.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image.pixels); // NOTE: Not using mipmappings (texture for 2D drawing) @@ -329,6 +293,12 @@ void DrawTexture(Texture2D texture, int posX, int posY, Color tint) DrawTextureEx(texture, (Vector2){ (float)posX, (float)posY}, 0, 1.0f, tint); } +// Draw a Texture2D with position defined as Vector2 +void DrawTextureV(Texture2D texture, Vector2 position, Color tint) +{ + DrawTextureEx(texture, position, 0, 1.0f, tint); +} + // Draw a Texture2D with extended parameters void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint) { diff --git a/src/vector3.c b/src/vector3.c index 378ab877..6b0e1573 100644 --- a/src/vector3.c +++ b/src/vector3.c @@ -25,7 +25,7 @@ #include "vector3.h" -#include +#include // Used for fabs(), sqrt() // Add two vectors Vector3 VectorAdd(Vector3 v1, Vector3 v2) diff --git a/tests/heightmap.png b/tests/heightmap.png new file mode 100644 index 0000000000000000000000000000000000000000..c17050fcc2dc470a46306ec1994a8e9b08e5458d GIT binary patch literal 1362 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|k|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?iUDV2pMQ*9U+m=!WZB1$5BeXNr6bM+EIYV;~{3xK*A7;Nk-3KEmEQ%e+* zQqwc@Y?a>c-mj#PnPRIHZt82`Ti~3Uk?B!Ylp0*+7m{3+ootz+WN)WnQ(*-(AUCxn zQK2F?C$HG5!d3}vt`(3C64qBz04piUwpD^SD#ABF!8yMuRl!uxKsVXI%s|1+P|wiV z#N6CmN5ROz&_Lh7NZ-&%*U;R`*vQJjKmiJrfVLH-q*(>IxIyg#@@$ndN=gc>^!3Zj z%k|2Q_413-^$jg8EkR}&8R-I5=oVMzl_XZ^<`pZ$OmImpPAEg{v+u2}(t{7puX=A(aKG z`a!A1`K3k4z=%sz23b{LACkqn`6H_xoLsw%*Q$u4%OJ`RXLnl`k z15$o& z6x?nx#;I2y=oo!av?4__ObD2EKuma|1#;lYJ~a=R){B6N`VmX%KL!TI6P_-PAr-fL zCSC74*}w~k0tMC$5$t@Y?--C zlB+doqlBGM=L6ou6?XG~xF`j#zIy8Erqsx}e(sHYY|Re~BuccVdZ|rTh`G-Ct8V|t ziy2#P=4^}7O_=vwGi&#)Pd{sx25E|Q-^`h&{C)lP*B>hco)qn@uvs@{(av9&rkzZ2 zFqi5LTIu3rXchdg#_oQedDFp!g1vFod*^M+l{VW^wKr~U*yWcdQUM)Fr-bA6rhl!n zmFj)4<#w*Cq13|V0U8QyMhYs542NEp2tBK?nRotq#Zf1Tr_r+?TO8r(^+@@#&%gf9 z#|jnJ$$K@0NPPEr)XKzzz-F92o zLhO|P#kXZEvlqs>bbF~SHpuuDP--@tx7~Sxzye({?pB>sC)g%<2gl9oEo|}3GMf42 zckR6y4Nmjt_ji8(ZM#+>I7n{xHh}>9xqdrcB-|O=at>cRCVy~WrP!%rk=!du5{}J( a1QQq-%bWyx)eE+QN;ywgKbLh*2~7ZNNa?Ns literal 0 HcmV?d00001 diff --git a/tests/test_billboard.c b/tests/test_billboard.c new file mode 100644 index 00000000..99cf0f33 --- /dev/null +++ b/tests/test_billboard.c @@ -0,0 +1,77 @@ +/******************************************************************************************* +* +* raylib test - Testing DrawBillboard() and DrawBillboardRec() +* +* 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) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + Vector3 position = { 0.0, 0.0, 0.0 }; + + // Define the camera to look into our 3d world + Camera camera = {{ 10.0, 8.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }}; + + InitWindow(screenWidth, screenHeight, "raylib test - Billboards"); + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + + Texture2D texture = LoadTexture("resources/raylib_logo.png"); + Texture2D lena = LoadTexture("resources/lena.png"); + + Rectangle eyesRec = { 225, 240, 155, 50 }; + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + if (IsKeyDown(KEY_LEFT)) camera.position.x -= 0.2; + if (IsKeyDown(KEY_RIGHT)) camera.position.x += 0.2; + if (IsKeyDown(KEY_UP)) camera.position.y -= 0.2; + if (IsKeyDown(KEY_DOWN)) camera.position.y += 0.2; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + Begin3dMode(camera); + + //DrawBillboard(camera, texture, position, 2.0, WHITE); + DrawBillboardRec(camera, lena, eyesRec, position, 4.0, WHITE); + + DrawGrid(10.0, 1.0); // Draw a grid + + End3dMode(); + + DrawFPS(10, 10); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(texture); // Unload texture + UnloadTexture(lena); // Unload texture + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} \ No newline at end of file diff --git a/tests/test_formattext.c b/tests/test_formattext.c new file mode 100644 index 00000000..c74e76a7 --- /dev/null +++ b/tests/test_formattext.c @@ -0,0 +1,62 @@ +/******************************************************************************************* +* +* raylib test - Testing FormatText() function +* +* 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) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + int score = 100020; + int hiscore = 200450; + int lives = 5; + + InitWindow(screenWidth, screenHeight, "raylib test - FormatText()"); + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // TODO: Update your variables here + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawText(FormatText("Score: %08i", score), 80, 80, 20, RED); + + DrawText(FormatText("HiScore: %08i", hiscore), 80, 120, 20, GREEN); + + DrawText(FormatText("Lives: %02i", lives), 80, 160, 40, BLUE); + + DrawText(FormatText("Elapsed Time: %02.02f ms", GetFrameTime()*1000), 80, 220, 20, BLACK); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} \ No newline at end of file diff --git a/tests/test_heightmap.c b/tests/test_heightmap.c new file mode 100644 index 00000000..890bc0a4 --- /dev/null +++ b/tests/test_heightmap.c @@ -0,0 +1,76 @@ +/******************************************************************************************* +* +* raylib test - Testing Heightmap Loading and Drawing +* +* 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) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + Vector3 position = { 0.0, 0.0, 0.0 }; + + // Define the camera to look into our 3d world + Camera camera = {{ 12.0, 10.0, 12.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }}; + + InitWindow(screenWidth, screenHeight, "raylib test - Heightmap loading and drawing"); + + Image img = LoadImage("heightmap.png"); + Model map = LoadHeightmap(img, 4); + Texture2D tex = CreateTexture(img); + UnloadImage(img); + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // ... + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + Begin3dMode(camera); + + //DrawModel(map, position, 0.5f, MAROON); + DrawModelEx(map, tex, position, 0.5f, WHITE); // Draw 3d model with texture + + DrawGrid(10.0, 1.0); // Draw a grid + + DrawGizmo(position, false); + + End3dMode(); + + DrawFPS(10, 10); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(tex); // Unload texture + UnloadModel(map); // Unload model + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} \ No newline at end of file diff --git a/tests/test_image_loading.c b/tests/test_image_loading.c new file mode 100644 index 00000000..c554a394 --- /dev/null +++ b/tests/test_image_loading.c @@ -0,0 +1,60 @@ +/******************************************************************************************* +* +* raylib test - Testing LoadImage() and CreateTexture() +* +* 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) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib test - Image loading"); + + // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) + + Image img = LoadImage("resources/raylib_logo.png"); + Texture2D texture = CreateTexture(img); + UnloadImage(img); + //--------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // TODO: Update your variables here + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE); + + DrawText("this IS a texture!", 360, 370, 10, GRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(texture); // Texture unloading + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} \ No newline at end of file diff --git a/tests/test_mouse_wheel.c b/tests/test_mouse_wheel.c new file mode 100644 index 00000000..0acbb0f8 --- /dev/null +++ b/tests/test_mouse_wheel.c @@ -0,0 +1,57 @@ +/******************************************************************************************* +* +* raylib test - Testing GetMouseWheelMove() +* +* 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) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib test - Mouse wheel"); + + int positionY = 0; + int scrollSpeed = 4; // Scrolling speed in pixels + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + positionY -= (GetMouseWheelMove()*scrollSpeed); + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawRectangle(200, positionY, 80, 80, MAROON); + + DrawText(FormatText("%i", positionY), 10, 10, 20, GRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} \ No newline at end of file diff --git a/tests/test_random.c b/tests/test_random.c new file mode 100644 index 00000000..b44bf1db --- /dev/null +++ b/tests/test_random.c @@ -0,0 +1,62 @@ +/******************************************************************************************* +* +* raylib test - Testing GetRandomValue() +* +* 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) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + int framesCounter = 0; + + InitWindow(screenWidth, screenHeight, "raylib test - Random numbers"); + + int randValue = GetRandomValue(-8,5); + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + framesCounter++; + + if ((framesCounter/60)%2) + { + randValue = GetRandomValue(-8,5); + framesCounter = 0; + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawText(FormatText("%i", randValue), 120, 120, 60, LIGHTGRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} \ No newline at end of file