summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--examples/core_3d_camera_free.c2
-rw-r--r--examples/textures_formats_loading.c14
-rw-r--r--src/core.c92
-rw-r--r--src/gestures.c63
-rw-r--r--src/raylib.h7
-rw-r--r--src/rlgl.c3
-rw-r--r--src/textures.c8
7 files changed, 120 insertions, 69 deletions
diff --git a/examples/core_3d_camera_free.c b/examples/core_3d_camera_free.c
index cca9cfd5..be44ed2a 100644
--- a/examples/core_3d_camera_free.c
+++ b/examples/core_3d_camera_free.c
@@ -44,7 +44,7 @@ int main()
//----------------------------------------------------------------------------------
BeginDrawing();
- ClearBackground(WHITE);
+ ClearBackground(RAYWHITE);
Begin3dMode(camera);
diff --git a/examples/textures_formats_loading.c b/examples/textures_formats_loading.c
index a758fe27..f416ce38 100644
--- a/examples/textures_formats_loading.c
+++ b/examples/textures_formats_loading.c
@@ -76,7 +76,7 @@ int main()
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
- int screenHeight = 480;
+ int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture formats loading");
@@ -128,8 +128,8 @@ int main()
for (int i = 0; i < NUM_TEXTURES; i++)
{
- if (i < NUM_TEXTURES/2) selectRecs[i] = (Rectangle){ 40, 45 + 32*i, 150, 30 };
- else selectRecs[i] = (Rectangle){ 40 + 152, 45 + 32*(i - NUM_TEXTURES/2), 150, 30 };
+ if (i < NUM_TEXTURES/2) selectRecs[i] = (Rectangle){ 40, 30 + 32*i, 150, 30 };
+ else selectRecs[i] = (Rectangle){ 40 + 152, 30 + 32*(i - NUM_TEXTURES/2), 150, 30 };
}
// Texture sizes in KB
@@ -215,7 +215,7 @@ int main()
// Draw selected texture
if (sonic[selectedFormat].id != 0)
{
- DrawTexture(sonic[selectedFormat], 350, 0, WHITE);
+ DrawTexture(sonic[selectedFormat], 350, -10, WHITE);
}
else
{
@@ -225,9 +225,9 @@ int main()
DrawText("ON YOUR GPU", 520, 240, 20, MAROON);
}
- DrawText("Select texture format (use cursor keys):", 40, 26, 10, DARKGRAY);
- DrawText("Required GPU memory size (VRAM):", 40, 442, 10, DARKGRAY);
- DrawText(FormatText("%4.0f KB", textureSizes[selectedFormat]), 240, 435, 20, DARKBLUE);
+ DrawText("Select texture format (use cursor keys):", 40, 10, 10, DARKGRAY);
+ DrawText("Required GPU memory size (VRAM):", 40, 427, 10, DARKGRAY);
+ DrawText(FormatText("%4.0f KB", textureSizes[selectedFormat]), 240, 420, 20, DARKBLUE);
EndDrawing();
//----------------------------------------------------------------------------------
diff --git a/src/core.c b/src/core.c
index 47bce873..b2d94506 100644
--- a/src/core.c
+++ b/src/core.c
@@ -95,6 +95,11 @@
#define DEFAULT_GAMEPAD_DEV "/dev/input/js0"
#endif
+#if defined(PLATFORM_WEB)
+ #include <emscripten/emscripten.h>
+ #include <emscripten/html5.h>
+#endif
+
//----------------------------------------------------------------------------------
// Defines and Macros
//----------------------------------------------------------------------------------
@@ -158,6 +163,10 @@ static int renderOffsetY = 0; // Offset Y from render area (must b
static bool fullscreen = false; // Fullscreen mode (useful only for PLATFORM_DESKTOP)
static Matrix downscaleView; // Matrix to downscale view (in case screen size bigger than display size)
+#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
+static Vector2 touchPosition; // Touch position on screen
+#endif
+
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB)
static const char *windowTitle; // Window text title...
@@ -247,6 +256,10 @@ static void TakeScreenshot(void);
static void AndroidCommandCallback(struct android_app *app, int32_t cmd); // Process Android activity lifecycle commands
#endif
+#if defined(PLATFORM_WEB)
+static EM_BOOL EmscriptenFullscreenChangeCallback(int eventType, const EmscriptenFullscreenChangeEvent *e, void *userData);
+#endif
+
//----------------------------------------------------------------------------------
// Module Functions Definition - Window and OpenGL Context Functions
//----------------------------------------------------------------------------------
@@ -279,6 +292,12 @@ void InitWindow(int width, int height, const char *title)
InitGamepad(); // Gamepad init
#endif
+#if defined(PLATFORM_WEB)
+ InitGesturesSystem();
+
+ emscripten_set_fullscreenchange_callback(0, 0, 1, EmscriptenFullscreenChangeCallback);
+#endif
+
mousePosition.x = screenWidth/2;
mousePosition.y = screenHeight/2;
@@ -335,6 +354,8 @@ void InitWindow(int width, int height, struct android_app *state)
//InitGesturesSystem(app); // NOTE: Must be called by user
InitAssetManager(app->activity->assetManager);
+
+ InitGesturesSystem(app);
TraceLog(INFO, "Android app initialized successfully");
@@ -499,7 +520,7 @@ void EndDrawing(void)
SwapBuffers(); // Copy back buffer to front buffer
PollInputEvents(); // Poll user events
-
+
currentTime = GetTime();
drawTime = currentTime - previousTime;
previousTime = currentTime;
@@ -814,7 +835,7 @@ Vector2 GetMousePosition(void)
void SetMousePosition(Vector2 position)
{
mousePosition = position;
-#if defined(PLATFORM_DESKTOP)
+#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
// NOTE: emscripten not implemented
glfwSetCursorPos(window, position.x, position.y);
#endif
@@ -969,6 +990,41 @@ bool IsGamepadButtonUp(int gamepad, int button)
}
#endif
+#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
+// Returns touch position X
+int GetTouchX(void)
+{
+ return (int)touchPosition.x;
+}
+
+// Returns touch position Y
+int GetTouchY(void)
+{
+ return (int)touchPosition.y;
+}
+
+// Returns touch position XY
+// TODO: touch position should be scaled depending on display size and render size
+Vector2 GetTouchPosition(void)
+{
+ Vector2 position = touchPosition;
+
+ if ((screenWidth > displayWidth) || (screenHeight > displayHeight))
+ {
+ // TODO: Seems to work ok but... review!
+ position.x = position.x*((float)screenWidth/(float)(displayWidth - renderOffsetX)) - renderOffsetX/2;
+ position.y = position.y*((float)screenHeight/(float)(displayHeight - renderOffsetY)) - renderOffsetY/2;
+ }
+ else
+ {
+ position.x = position.x*((float)renderWidth/(float)displayWidth) - renderOffsetX/2;
+ position.y = position.y*((float)renderHeight/(float)displayHeight) - renderOffsetY/2;
+ }
+
+ return position;
+}
+#endif
+
//----------------------------------------------------------------------------------
// Module specific Functions Definition
//----------------------------------------------------------------------------------
@@ -1547,6 +1603,13 @@ static bool GetMouseButtonStatus(int button)
// Poll (store) all input events
static void PollInputEvents(void)
{
+#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
+ // Touch events reading (requires gestures module)
+ touchPosition = GetRawTouchPosition();
+
+ UpdateGestures();
+#endif
+
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
// Mouse input polling
double mouseX;
@@ -1940,6 +2003,31 @@ static void SetupFramebufferSize(int displayWidth, int displayHeight)
}
}
+#if defined(PLATFORM_WEB)
+static EM_BOOL EmscriptenFullscreenChangeCallback(int eventType, const EmscriptenFullscreenChangeEvent *e, void *userData)
+{
+ //isFullscreen: int e->isFullscreen
+ //fullscreenEnabled: int e->fullscreenEnabled
+ //fs element nodeName: (char *) e->nodeName
+ //fs element id: (char *) e->id
+ //Current element size: (int) e->elementWidth, (int) e->elementHeight
+ //Screen size:(int) e->screenWidth, (int) e->screenHeight
+
+ if (e->isFullscreen)
+ {
+ TraceLog(INFO, "Canvas scaled to fullscreen. ElementSize: (%ix%i), ScreenSize(%ix%i)", e->elementWidth, e->elementHeight, e->screenWidth, e->screenHeight);
+ }
+ else
+ {
+ TraceLog(INFO, "Canvas scaled to windowed. ElementSize: (%ix%i), ScreenSize(%ix%i)", e->elementWidth, e->elementHeight, e->screenWidth, e->screenHeight);
+ }
+
+ // TODO: Depending on scaling factor (screen vs element), calculate factor to scale mouse/touch input
+
+ return 0;
+}
+#endif
+
// Plays raylib logo appearing animation
static void LogoAnimation(void)
{
diff --git a/src/gestures.c b/src/gestures.c
index 61660571..f5e8c62f 100644
--- a/src/gestures.c
+++ b/src/gestures.c
@@ -122,7 +122,7 @@ static int currentGesture = GESTURE_NONE;
static unsigned int enabledGestures = 0; // TODO: Currently not in use...
-static Vector2 touchPosition;
+static Vector2 rawTouchPosition;
//----------------------------------------------------------------------------------
// Module specific Functions Declaration
@@ -147,55 +147,15 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
// Module Functions Definition
//----------------------------------------------------------------------------------
-// Returns touch position X
-int GetTouchX(void)
+// Get touch position (could require further processing depending on display size)
+Vector2 GetRawTouchPosition(void)
{
- return (int)touchPosition.x;
-}
-
-// Returns touch position Y
-int GetTouchY(void)
-{
- return (int)touchPosition.y;
-}
-
-// Returns touch position XY
-// TODO: touch position should be scaled depending on display size and render size
-Vector2 GetTouchPosition(void)
-{
- Vector2 position = touchPosition;
-/*
- if ((screenWidth > displayWidth) || (screenHeight > displayHeight))
- {
- // TODO: Seems to work ok but... review!
- position.x = position.x*((float)screenWidth / (float)(displayWidth - renderOffsetX)) - renderOffsetX/2;
- position.y = position.y*((float)screenHeight / (float)(displayHeight - renderOffsetY)) - renderOffsetY/2;
- }
- else
- {
- position.x = position.x*((float)renderWidth / (float)displayWidth) - renderOffsetX/2;
- position.y = position.y*((float)renderHeight / (float)displayHeight) - renderOffsetY/2;
- }
-*/
- return position;
+ return rawTouchPosition;
}
// Check if a gesture have been detected
bool IsGestureDetected(void)
{
-/*
- if (currentGesture == GESTURE_DRAG) TraceLog(INFO, "DRAG");
- else if (currentGesture == GESTURE_TAP) TraceLog(INFO, "TAP");
- else if (currentGesture == GESTURE_DOUBLETAP) TraceLog(INFO, "DOUBLE");
- else if (currentGesture == GESTURE_HOLD) TraceLog(INFO, "HOLD");
- else if (currentGesture == GESTURE_SWIPE_RIGHT) TraceLog(INFO, "RIGHT");
- else if (currentGesture == GESTURE_SWIPE_UP) TraceLog(INFO, "UP");
- else if (currentGesture == GESTURE_SWIPE_LEFT) TraceLog(INFO, "LEFT");
- else if (currentGesture == GESTURE_SWIPE_DOWN) TraceLog(INFO, "DOWN");
- else if (currentGesture == GESTURE_PINCH_IN) TraceLog(INFO, "PINCH IN");
- else if (currentGesture == GESTURE_PINCH_OUT) TraceLog(INFO, "PINCH OUT");
-*/
-
if (currentGesture != GESTURE_NONE) return true;
else return false;
}
@@ -382,7 +342,7 @@ static void ProcessMotionEvent(GestureEvent event)
{
lastDragPosition = endDragPosition;
- endDragPosition = touchPosition;
+ endDragPosition = rawTouchPosition;
//endDragPosition.x = AMotionEvent_getX(event, 0);
//endDragPosition.y = AMotionEvent_getY(event, 0);
@@ -594,8 +554,8 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
if (type == AINPUT_EVENT_TYPE_MOTION)
{
- touchPosition.x = AMotionEvent_getX(event, 0);
- touchPosition.y = AMotionEvent_getY(event, 0);
+ rawTouchPosition.x = AMotionEvent_getX(event, 0);
+ rawTouchPosition.y = AMotionEvent_getY(event, 0);
}
else if (type == AINPUT_EVENT_TYPE_KEY)
{
@@ -676,10 +636,13 @@ static EM_BOOL EmscriptenInputCallback(int eventType, const EmscriptenTouchEvent
gestureEvent.pointCount = touchEvent->numTouches;
// Position
- gestureEvent.position[0] = (Vector2){ touchEvent->touches[0].canvasX, touchEvent->touches[0].canvasY };
- gestureEvent.position[1] = (Vector2){ touchEvent->touches[1].canvasX, touchEvent->touches[1].canvasY };
+ //gestureEvent.position[0] = (Vector2){ touchEvent->touches[0].canvasX, touchEvent->touches[0].canvasY };
+ //gestureEvent.position[1] = (Vector2){ touchEvent->touches[1].canvasX, touchEvent->touches[1].canvasY };
+ gestureEvent.position[0] = (Vector2){ touchEvent->touches[0].targetX, touchEvent->touches[0].targetY };
+ gestureEvent.position[1] = (Vector2){ touchEvent->touches[1].targetX, touchEvent->touches[1].targetY };
+ printf("EVENT DETECTED!\n");
- touchPosition = gestureEvent.position[0];
+ rawTouchPosition = gestureEvent.position[0];
ProcessMotionEvent(gestureEvent);
diff --git a/src/raylib.h b/src/raylib.h
index 15642256..419989d0 100644
--- a/src/raylib.h
+++ b/src/raylib.h
@@ -496,13 +496,14 @@ bool IsGamepadButtonUp(int gamepad, int button); // Detect if a gamepad b
#endif
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
-//------------------------------------------------------------------------------------
-// Gestures and Touch Handling Functions (Module: gestures)
-//------------------------------------------------------------------------------------
int GetTouchX(void); // Returns touch position X (relative to screen size)
int GetTouchY(void); // Returns touch position Y (relative to screen size)
Vector2 GetTouchPosition(void); // Returns touch position XY (relative to screen size)
+//------------------------------------------------------------------------------------
+// Gestures and Touch Handling Functions (Module: gestures)
+//------------------------------------------------------------------------------------
+Vector2 GetRawTouchPosition(void); // Gewt touch position (raw)
#if defined(PLATFORM_WEB)
void InitGesturesSystem(void); // Init gestures system (web)
#elif defined(PLATFORM_ANDROID)
diff --git a/src/rlgl.c b/src/rlgl.c
index 797833e6..ebff0d53 100644
--- a/src/rlgl.c
+++ b/src/rlgl.c
@@ -1008,7 +1008,8 @@ void rlglInit(void)
#endif
// DDS texture compression support
- if (strcmp(extList[i], (const char *)"GL_EXT_texture_compression_s3tc") == 0) texCompDXTSupported = true;
+ if ((strcmp(extList[i], (const char *)"GL_EXT_texture_compression_s3tc") == 0) ||
+ (strcmp(extList[i], (const char *)"GL_WEBKIT_WEBGL_compressed_texture_s3tc") == 0)) texCompDXTSupported = true;
// ETC1 texture compression support
if (strcmp(extList[i], (const char *)"GL_OES_compressed_ETC1_RGB8_texture") == 0) texCompETC1Supported = true;
diff --git a/src/textures.c b/src/textures.c
index 66d2afc5..007547ca 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -1028,8 +1028,6 @@ void ImageColorTint(Image *image, Color color)
UnloadImage(*image);
free(pixels);
- TraceLog(INFO,"color tint applied");
-
image->data = processed.data;
}
@@ -1160,11 +1158,11 @@ void ImageColorBrightness(Image *image, int brightness)
void GenTextureMipmaps(Texture2D texture)
{
#if PLATFORM_WEB
- int potWidth = GetNextPOT(image->width);
- int potHeight = GetNextPOT(image->height);
+ int potWidth = GetNextPOT(texture.width);
+ int potHeight = GetNextPOT(texture.height);
// Check if texture is POT
- if ((potWidth != image->width) || (potHeight != image->height))
+ if ((potWidth != texture.width) || (potHeight != texture.height))
{
TraceLog(WARNING, "Limited NPOT support, no mipmaps available for NPOT textures");
}