diff --git a/src/core.c b/src/core.c index dec08eebd..62ab5cbb4 100644 --- a/src/core.c +++ b/src/core.c @@ -165,7 +165,7 @@ static const char *windowTitle; // Window text title... static char configFlags = 0; static bool customCursor = false; // Tracks if custom cursor has been set -static bool cursorOnScreen = true; // Tracks if cursor is inside client area +static bool cursorOnScreen = false; // Tracks if cursor is inside client area static Texture2D cursor; // Cursor texture static Vector2 mousePosition; @@ -727,6 +727,15 @@ Vector2 GetMousePosition(void) return mousePosition; } +// Set mouse position XY +void SetMousePosition(Vector2 position) +{ + mousePosition = position; +#if defined(PLATFORM_DESKTOP) + glfwSetCursorPos(window, position.x, position.y); +#endif +} + // Returns mouse wheel movement Y int GetMouseWheelMove(void) { diff --git a/src/makefile b/src/makefile index bb37748ab..2a9050524 100644 --- a/src/makefile +++ b/src/makefile @@ -24,7 +24,7 @@ #************************************************************************************************** # define raylib platform (by default, compile for RPI) -# Other possible platforms: PLATFORM_DESKTOP PLATFORM_DESKTOP_LINUX +# Other possible platforms: PLATFORM_DESKTOP_WIN PLATFORM_DESKTOP_LINUX PLATFORM_WEB PLATFORM ?= PLATFORM_RPI # define raylib graphics api depending on selected platform @@ -40,16 +40,26 @@ endif # NOTE: makefiles targets require tab indentation # define compiler: gcc for C program, define as g++ for C++ -CC = gcc +ifeq ($(PLATFORM),PLATFORM_WEB) + # define emscripten compiler + CC = emcc +else + # define default gcc compiler + CC = gcc +endif # define compiler flags: # -O2 defines optimization level # -Wall turns on most, but not all, compiler warnings # -std=c99 use standard C from 1999 revision +ifeq ($(PLATFORM),PLATFORM_WEB) + CFLAGS = -O3 -s USE_GLFW=3 -s LEGACY_GL_EMULATION=1 +else ifeq ($(PLATFORM),PLATFORM_RPI) CFLAGS = -O2 -Wall -std=gnu99 -fgnu89-inline else - CFLAGS = -O2 -Wall -std=c99 -fgnu89-inline + CFLAGS = -O2 -Wall -std=c99 +endif endif #CFLAGSEXTRA = -Wextra -Wmissing-prototypes -Wstrict-prototypes @@ -69,11 +79,16 @@ default: raylib # compile raylib library raylib: $(OBJS) +ifeq ($(PLATFORM),PLATFORM_WEB) + emcc $(OBJS) -o raylib.bc +else ar rcs libraylib.a $(OBJS) +endif # compile core module +# emcc core.c -o core.bc -DPLATFORM_DESKTOP core.o: core.c - $(CC) -c core.c $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + $(CC) -c core.c $(CFLAGS) $(INCLUDES) -D$(PLATFORM) -D$(GRAPHICS) # compile rlgl module rlgl.o: rlgl.c @@ -85,19 +100,19 @@ raymath.o: raymath.c # compile shapes module shapes.o: shapes.c - $(CC) -c shapes.c $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + $(CC) -c shapes.c $(CFLAGS) $(INCLUDES) -D$(PLATFORM) -D$(GRAPHICS) # compile textures module textures.o: textures.c - $(CC) -c textures.c $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + $(CC) -c textures.c $(CFLAGS) $(INCLUDES) -D$(PLATFORM) -D$(GRAPHICS) # compile text module text.o: text.c - $(CC) -c text.c $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + $(CC) -c text.c $(CFLAGS) $(INCLUDES) -D$(PLATFORM) -D$(GRAPHICS) # compile models module models.o: models.c - $(CC) -c models.c $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + $(CC) -c models.c $(CFLAGS) $(INCLUDES) -D$(PLATFORM) -D$(GRAPHICS) # compile audio module audio.o: audio.c diff --git a/src/models.c b/src/models.c index 2d2af038c..f59a7b43c 100644 --- a/src/models.c +++ b/src/models.c @@ -743,7 +743,7 @@ Model LoadHeightmap(Image heightmap, float maxHeight) vData.texcoords[tcCounter + 7] = vData.texcoords[tcCounter + 5]; vData.texcoords[tcCounter + 8] = vData.texcoords[tcCounter + 2]; - vData.texcoords[tcCounter + 9] = vData.texcoords[tcCounter + 1]; + vData.texcoords[tcCounter + 9] = vData.texcoords[tcCounter + 3]; vData.texcoords[tcCounter + 10] = (float)(x+1) / (mapX-1); vData.texcoords[tcCounter + 11] = (float)(z+1) / (mapZ-1); diff --git a/src/raylib.h b/src/raylib.h index 9809d8234..e7ef32178 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -340,6 +340,7 @@ bool IsMouseButtonUp(int button); // Detect if a mouse but int GetMouseX(void); // Returns mouse position X int GetMouseY(void); // Returns mouse position Y Vector2 GetMousePosition(void); // Returns mouse position XY +void SetMousePosition(Vector2 position); // Set mouse position XY int GetMouseWheelMove(void); // Returns mouse wheel movement Y bool IsGamepadAvailable(int gamepad); // Detect if a gamepad is available diff --git a/src/raymath.h b/src/raymath.h index c396a347d..334df4f30 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -108,8 +108,8 @@ Matrix MatrixAdd(Matrix left, Matrix right); // Add two matrices Matrix MatrixSubstract(Matrix left, Matrix right); // Substract two matrices (left - right) Matrix MatrixTranslate(float x, float y, float z); // Returns translation matrix Matrix MatrixRotate(float angleX, float angleY, float angleZ); // Returns rotation matrix -Matrix MatrixRotateAroundAxis(Vector3 axis, float angle); // Returns rotation matrix for an angle around an specified axis -Matrix MatrixRotateAroundAxis2(Vector3 axis, float angle); // Returns rotation matrix for an angle around an specified axis (test another implemntation) +Matrix MatrixFromAxisAngle(Vector3 axis, float angle); // Returns rotation matrix for an angle around an specified axis +Matrix MatrixFromAxisAngle2(Vector3 axis, float angle); // Returns rotation matrix for an angle around an specified axis (test another implemntation) Matrix MatrixFromQuaternion(Quaternion q); // Returns rotation matrix for a given quaternion Matrix MatrixRotateX(float angle); // Returns x-rotation matrix (angle in radians) Matrix MatrixRotateY(float angle); // Returns y-rotation matrix (angle in radians) diff --git a/src/rlgl.c b/src/rlgl.c index 5e51b2e2b..cfb33989b 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -301,6 +301,10 @@ void rlRotatef(float angleDeg, float x, float y, float z) if (x == 1) rot = MatrixRotateX(angleDeg*DEG2RAD); else if (y == 1) rot = MatrixRotateY(angleDeg*DEG2RAD); else if (z == 1) rot = MatrixRotateZ(angleDeg*DEG2RAD); + + //Vector3 vec = (Vector3){ 0, 0, 1 }; + //VectorNormalize(&vec); + //rot = MatrixFromAxisAngle(vec, angleDeg*DEG2RAD); // Working MatrixTranspose(&rot); @@ -1305,7 +1309,8 @@ unsigned int rlglLoadTexture(unsigned char *data, int width, int height, bool ge #if defined(GRAPHICS_API_OPENGL_33) // NOTE: We define internal (GPU) format as GL_RGBA8 (probably BGRA8 in practice, driver takes care) - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); + //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); // OpenGL + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); // WebGL #elif defined(GRAPHICS_API_OPENGL_ES2) // NOTE: On embedded systems, we let the driver choose the best internal format glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); @@ -1562,6 +1567,7 @@ static GLuint LoadDefaultShaders(void) char fShaderStr[] = " #version 110 \n" // NOTE: Equivalent to version 100 on ES2 #elif defined(GRAPHICS_API_OPENGL_ES2) char fShaderStr[] = " #version 100 \n" // NOTE: Must be defined this way! 110 doesn't work! + "precision mediump float; \n" // WebGL, required for emscripten #endif "uniform sampler2D texture0; \n" "varying vec2 fragTexCoord; \n"