Просмотр исходного кода

Merge remote-tracking branch 'refs/remotes/raysan5/develop' into develop

pull/75/head
Joshua Reisenauer 10 лет назад
Родитель
Сommit
38c0f75c43
7 измененных файлов: 120 добавлений и 69 удалений
  1. +1
    -1
      examples/core_3d_camera_free.c
  2. +7
    -7
      examples/textures_formats_loading.c
  3. +90
    -2
      src/core.c
  4. +13
    -50
      src/gestures.c
  5. +4
    -3
      src/raylib.h
  6. +2
    -1
      src/rlgl.c
  7. +3
    -5
      src/textures.c

+ 1
- 1
examples/core_3d_camera_free.c Просмотреть файл

@ -44,7 +44,7 @@ int main()
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(WHITE);
ClearBackground(RAYWHITE);
Begin3dMode(camera);

+ 7
- 7
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, o">-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();
//----------------------------------------------------------------------------------

+ 90
- 2
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)
{

+ 13
- 50
src/gestures.c Просмотреть файл

@ -123,7 +123,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
@ -148,55 +148,15 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
// Module Functions Definition
//----------------------------------------------------------------------------------
// Returns touch position X
kt">int GetTouchX(void)
// Get touch position (could require further processing depending on display size)
n">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;
}
@ -383,7 +343,7 @@ static void ProcessMotionEvent(GestureEvent event)
{
lastDragPosition = endDragPosition;
endDragPosition = touchPosition;
endDragPosition = rawTouchPosition;
//endDragPosition.x = AMotionEvent_getX(event, 0);
//endDragPosition.y = AMotionEvent_getY(event, 0);
@ -595,8 +555,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)
{
@ -677,10 +637,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);

+ 4
- 3
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)

+ 2
- 1
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;

+ 3
- 5
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");
}

Загрузка…
Отмена
Сохранить