Jelajahi Sumber

Added features and corrected bugs...

[core] Added SetMousePosition()
[models] LoadHeightmap() - Corrected textures bug
[raymath] Functions renaming
[WEB] Prepare environment for emscripten!
raysan5 10 tahun lalu
induk
melakukan
d3cf316e40
6 mengubah file dengan 44 tambahan dan 13 penghapusan
  1. 10 1
      src/core.c
  2. 23 8
      src/makefile
  3. 1 1
      src/models.c
  4. 1 0
      src/raylib.h
  5. 2 2
      src/raymath.h
  6. 7 1
      src/rlgl.c

+ 10 - 1
src/core.c

@@ -165,7 +165,7 @@ static const char *windowTitle;             // Window text title...
 static char configFlags = 0;
 static char configFlags = 0;
 
 
 static bool customCursor = false;           // Tracks if custom cursor has been set
 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 Texture2D cursor;                    // Cursor texture
 
 
 static Vector2 mousePosition;
 static Vector2 mousePosition;
@@ -727,6 +727,15 @@ Vector2 GetMousePosition(void)
     return mousePosition;
     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
 // Returns mouse wheel movement Y
 int GetMouseWheelMove(void)
 int GetMouseWheelMove(void)
 {
 {

+ 23 - 8
src/makefile

@@ -24,7 +24,7 @@
 #**************************************************************************************************
 #**************************************************************************************************
 
 
 # define raylib platform (by default, compile for RPI)
 # 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
 PLATFORM ?= PLATFORM_RPI
 
 
 # define raylib graphics api depending on selected platform
 # define raylib graphics api depending on selected platform
@@ -40,16 +40,26 @@ endif
 # NOTE: makefiles targets require tab indentation
 # NOTE: makefiles targets require tab indentation
 
 
 # define compiler: gcc for C program, define as g++ for C++
 # 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:
 # define compiler flags:
 #  -O2         defines optimization level
 #  -O2         defines optimization level
 #  -Wall       turns on most, but not all, compiler warnings
 #  -Wall       turns on most, but not all, compiler warnings
 #  -std=c99    use standard C from 1999 revision
 #  -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)
 ifeq ($(PLATFORM),PLATFORM_RPI)
     CFLAGS = -O2 -Wall -std=gnu99 -fgnu89-inline
     CFLAGS = -O2 -Wall -std=gnu99 -fgnu89-inline
 else
 else
-    CFLAGS = -O2 -Wall -std=c99 -fgnu89-inline
+    CFLAGS = -O2 -Wall -std=c99
+endif
 endif
 endif
 #CFLAGSEXTRA = -Wextra -Wmissing-prototypes -Wstrict-prototypes
 #CFLAGSEXTRA = -Wextra -Wmissing-prototypes -Wstrict-prototypes
 
 
@@ -69,11 +79,16 @@ default: raylib
 
 
 # compile raylib library
 # compile raylib library
 raylib: $(OBJS)
 raylib: $(OBJS)
+ifeq ($(PLATFORM),PLATFORM_WEB)
+	emcc $(OBJS) -o raylib.bc
+else
 	ar rcs libraylib.a $(OBJS)
 	ar rcs libraylib.a $(OBJS)
+endif
 
 
 # compile core module
 # compile core module
+# emcc core.c -o core.bc -DPLATFORM_DESKTOP
 core.o: core.c
 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
 # compile rlgl module
 rlgl.o: rlgl.c
 rlgl.o: rlgl.c
@@ -85,19 +100,19 @@ raymath.o: raymath.c
 
 
 # compile shapes module
 # compile shapes module
 shapes.o: shapes.c
 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
 # compile textures module
 textures.o: textures.c
 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
 # compile text module
 text.o: text.c
 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
 # compile models module
 models.o: models.c
 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
 # compile audio module
 audio.o: audio.c
 audio.o: audio.c

+ 1 - 1
src/models.c

@@ -743,7 +743,7 @@ Model LoadHeightmap(Image heightmap, float maxHeight)
             vData.texcoords[tcCounter + 7] = vData.texcoords[tcCounter + 5];
             vData.texcoords[tcCounter + 7] = vData.texcoords[tcCounter + 5];
 
 
             vData.texcoords[tcCounter + 8] = vData.texcoords[tcCounter + 2];
             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 + 10] = (float)(x+1) / (mapX-1);
             vData.texcoords[tcCounter + 11] = (float)(z+1) / (mapZ-1);
             vData.texcoords[tcCounter + 11] = (float)(z+1) / (mapZ-1);

+ 1 - 0
src/raylib.h

@@ -340,6 +340,7 @@ bool IsMouseButtonUp(int button);                       // Detect if a mouse but
 int GetMouseX(void);                                    // Returns mouse position X
 int GetMouseX(void);                                    // Returns mouse position X
 int GetMouseY(void);                                    // Returns mouse position Y
 int GetMouseY(void);                                    // Returns mouse position Y
 Vector2 GetMousePosition(void);                         // Returns mouse position XY
 Vector2 GetMousePosition(void);                         // Returns mouse position XY
+void SetMousePosition(Vector2 position);                // Set mouse position XY
 int GetMouseWheelMove(void);                            // Returns mouse wheel movement Y
 int GetMouseWheelMove(void);                            // Returns mouse wheel movement Y
 
 
 bool IsGamepadAvailable(int gamepad);                   // Detect if a gamepad is available
 bool IsGamepadAvailable(int gamepad);                   // Detect if a gamepad is available

+ 2 - 2
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 MatrixSubstract(Matrix left, Matrix right);      // Substract two matrices (left - right)
 Matrix MatrixTranslate(float x, float y, float z);      // Returns translation matrix
 Matrix MatrixTranslate(float x, float y, float z);      // Returns translation matrix
 Matrix MatrixRotate(float angleX, float angleY, float angleZ); // Returns rotation 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 MatrixFromQuaternion(Quaternion q);              // Returns rotation matrix for a given quaternion
 Matrix MatrixRotateX(float angle);                      // Returns x-rotation matrix (angle in radians)
 Matrix MatrixRotateX(float angle);                      // Returns x-rotation matrix (angle in radians)
 Matrix MatrixRotateY(float angle);                      // Returns y-rotation matrix (angle in radians)
 Matrix MatrixRotateY(float angle);                      // Returns y-rotation matrix (angle in radians)

+ 7 - 1
src/rlgl.c

@@ -301,6 +301,10 @@ void rlRotatef(float angleDeg, float x, float y, float z)
     if (x == 1) rot = MatrixRotateX(angleDeg*DEG2RAD);
     if (x == 1) rot = MatrixRotateX(angleDeg*DEG2RAD);
     else if (y == 1) rot = MatrixRotateY(angleDeg*DEG2RAD);
     else if (y == 1) rot = MatrixRotateY(angleDeg*DEG2RAD);
     else if (z == 1) rot = MatrixRotateZ(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);
     MatrixTranspose(&rot);
 
 
@@ -1305,7 +1309,8 @@ unsigned int rlglLoadTexture(unsigned char *data, int width, int height, bool ge
 
 
 #if defined(GRAPHICS_API_OPENGL_33)
 #if defined(GRAPHICS_API_OPENGL_33)
     // NOTE: We define internal (GPU) format as GL_RGBA8 (probably BGRA8 in practice, driver takes care)
     // 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)
 #elif defined(GRAPHICS_API_OPENGL_ES2)
     // NOTE: On embedded systems, we let the driver choose the best internal format
     // 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);
     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
     char fShaderStr[] = " #version 110      \n"     // NOTE: Equivalent to version 100 on ES2
 #elif defined(GRAPHICS_API_OPENGL_ES2)
 #elif defined(GRAPHICS_API_OPENGL_ES2)
     char fShaderStr[] = " #version 100      \n"     // NOTE: Must be defined this way! 110 doesn't work!
     char fShaderStr[] = " #version 100      \n"     // NOTE: Must be defined this way! 110 doesn't work!
+        "precision mediump float;           \n"     // WebGL, required for emscripten
 #endif
 #endif
         "uniform sampler2D texture0;        \n"
         "uniform sampler2D texture0;        \n"
         "varying vec2 fragTexCoord;         \n"
         "varying vec2 fragTexCoord;         \n"