add egl support
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -34,5 +34,5 @@
|
||||
|
||||
/build
|
||||
/.vscode
|
||||
/xPlayer.*
|
||||
/xplayer*
|
||||
*.ini
|
||||
|
||||
4
.vscode/c_cpp_properties.json
vendored
4
.vscode/c_cpp_properties.json
vendored
@@ -20,12 +20,12 @@
|
||||
"name": "MinGW64",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**",
|
||||
"D:\\msys64\\mingw64\\include"
|
||||
"C:\\MinGW64\\include"
|
||||
],
|
||||
"defines": [
|
||||
"USE_OPENGL"
|
||||
],
|
||||
"compilerPath": "D:\\msys64\\mingw64\\bin\\gcc.exe",
|
||||
"compilerPath": "C:\\MinGW64\\bin\\gcc.exe",
|
||||
"cStandard": "c17",
|
||||
"cppStandard": "gnu++17",
|
||||
"intelliSenseMode": "windows-gcc-x64"
|
||||
|
||||
@@ -17,7 +17,7 @@ if (MPV_SW_RENDER)
|
||||
list(APPEND RENDER_DRIVER MPV_SW_RENDER)
|
||||
endif ()
|
||||
|
||||
project(xPlayer)
|
||||
project(xplayer)
|
||||
file(GLOB_RECURSE MAIN_SRC
|
||||
"${CMAKE_SOURCE_DIR}/src/*.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/imgui/*.cpp"
|
||||
|
||||
195
Makefile
195
Makefile
@@ -1,190 +1,25 @@
|
||||
#---------------------------------------------------------------------------------
|
||||
.SUFFIXES:
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET = xplayer
|
||||
|
||||
ifeq ($(strip $(DEVKITPRO)),)
|
||||
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
|
||||
endif
|
||||
|
||||
TOPDIR ?= $(CURDIR)
|
||||
include $(DEVKITPRO)/libnx/switch_rules
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET := xPlayer
|
||||
BUILD := build
|
||||
SRCS := src imgui
|
||||
DATA := data
|
||||
INCLUDES := imgui
|
||||
#ROMFS := romfs
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE
|
||||
CFLAGS := -g -Wall -O2 -ffunction-sections $(ARCH) $(DEFINES)
|
||||
CFLAGS += $(INCLUDE) -D__SWITCH__
|
||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -DIMGUI_IMPL_OPENGL_LOADER_CUSTOM
|
||||
ASFLAGS := -g $(ARCH)
|
||||
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
||||
LIBS := `$(PREFIX)pkg-config mpv --libs` \
|
||||
-lglfw3 -lEGL -lglapi -lglad -ldrm_nouveau -lm -lnx
|
||||
VPATH := $(foreach dir,$(SRCS),$(CURDIR)/$(dir))
|
||||
CPPFILES := $(foreach dir,$(SRCS),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
OFILES := $(CPPFILES:.cpp=.o)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS := $(PORTLIBS) $(LIBNX)
|
||||
INCLUDES := -I$(CURDIR)/imgui
|
||||
CFLAGS := -O2 -Wall $(INCLUDES) $(shell pkg-config --cflags glfw3)
|
||||
CXXFLAGS := $(CFLAGS) -std=c++17
|
||||
LDFLAGS := $(shell pkg-config mpv glfw3 --libs)
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# no real need to edit anything past this point unless you need to add additional
|
||||
# rules for different file extensions
|
||||
#---------------------------------------------------------------------------------
|
||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||
#---------------------------------------------------------------------------------
|
||||
$(TARGET): $(OFILES)
|
||||
$(CXX) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
export OUTPUT := $(CURDIR)/$(TARGET)
|
||||
export TOPDIR := $(CURDIR)
|
||||
run: all
|
||||
@./$(TARGET)
|
||||
|
||||
export VPATH := $(foreach dir,$(SRCS),$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||
|
||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||
|
||||
CFILES := $(foreach dir,$(SRCS),$(notdir $(wildcard $(dir)/*.c)))
|
||||
CPPFILES := $(foreach dir,$(SRCS),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
SFILES := $(foreach dir,$(SRCS),$(notdir $(wildcard $(dir)/*.s)))
|
||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# use CXX for linking C++ projects, CC for standard C
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(CPPFILES)),)
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CC)
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CXX)
|
||||
#---------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
|
||||
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
|
||||
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
|
||||
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I$(CURDIR)/$(BUILD)
|
||||
|
||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||
|
||||
ifeq ($(strip $(CONFIG_JSON)),)
|
||||
jsons := $(wildcard *.json)
|
||||
ifneq (,$(findstring $(TARGET).json,$(jsons)))
|
||||
export APP_JSON := $(TOPDIR)/$(TARGET).json
|
||||
else
|
||||
ifneq (,$(findstring config.json,$(jsons)))
|
||||
export APP_JSON := $(TOPDIR)/config.json
|
||||
endif
|
||||
endif
|
||||
else
|
||||
export APP_JSON := $(TOPDIR)/$(CONFIG_JSON)
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(ICON)),)
|
||||
icons := $(wildcard *.jpg)
|
||||
ifneq (,$(findstring $(TARGET).jpg,$(icons)))
|
||||
export APP_ICON := $(TOPDIR)/$(TARGET).jpg
|
||||
else
|
||||
ifneq (,$(findstring icon.jpg,$(icons)))
|
||||
export APP_ICON := $(TOPDIR)/icon.jpg
|
||||
endif
|
||||
endif
|
||||
else
|
||||
export APP_ICON := $(TOPDIR)/$(ICON)
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(NO_ICON)),)
|
||||
export NROFLAGS += --icon=$(APP_ICON)
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(NO_NACP)),)
|
||||
export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp
|
||||
endif
|
||||
|
||||
ifneq ($(APP_TITLEID),)
|
||||
export NACPFLAGS += --titleid=$(APP_TITLEID)
|
||||
endif
|
||||
|
||||
ifneq ($(ROMFS),)
|
||||
export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS)
|
||||
endif
|
||||
|
||||
.PHONY: $(BUILD) clean all
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
all: $(BUILD)
|
||||
|
||||
$(BUILD):
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
.PHONY: clean
|
||||
clean:
|
||||
@echo clean ...
|
||||
ifeq ($(strip $(APP_JSON)),)
|
||||
@rm -fr $(BUILD) $(TARGET).nro $(TARGET).nacp $(TARGET).elf
|
||||
else
|
||||
@rm -fr $(BUILD) $(TARGET).nsp $(TARGET).nso $(TARGET).npdm $(TARGET).elf
|
||||
endif
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
.PHONY: all
|
||||
|
||||
DEPENDS := $(OFILES:.o=.d)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(APP_JSON)),)
|
||||
|
||||
all : $(OUTPUT).nro
|
||||
|
||||
ifeq ($(strip $(NO_NACP)),)
|
||||
$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp
|
||||
else
|
||||
$(OUTPUT).nro : $(OUTPUT).elf
|
||||
endif
|
||||
|
||||
else
|
||||
|
||||
all : $(OUTPUT).nsp
|
||||
|
||||
$(OUTPUT).nsp : $(OUTPUT).nso $(OUTPUT).npdm
|
||||
|
||||
$(OUTPUT).nso : $(OUTPUT).elf
|
||||
|
||||
endif
|
||||
|
||||
$(OUTPUT).elf : $(OFILES)
|
||||
|
||||
$(OFILES_SRC) : $(HFILES_BIN)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# you need a rule like this for each extension you use as binary data
|
||||
#---------------------------------------------------------------------------------
|
||||
%.bin.o %_bin.h : %.bin
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
-include $(DEPENDS)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------------
|
||||
$(RM) $(OFILES) $(TARGET)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
TARGET = xPlayer
|
||||
TARGET = xplayer
|
||||
|
||||
BUILD := build
|
||||
SRCS := src imgui
|
||||
@@ -9,9 +9,10 @@ CPPFILES := $(foreach dir,$(SRCS),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o)
|
||||
|
||||
INCLUDES := -I$(CURDIR)/imgui
|
||||
CFLAGS := -O2 -Wall $(INCLUDES) `pkg-config --cflags glfw3`
|
||||
CFLAGS := -O2 -Wall $(INCLUDES) $(shell pkg-config --cflags glfw3)
|
||||
CXXFLAGS := $(CFLAGS) -std=c++17
|
||||
LDFLAGS := `pkg-config mpv glfw3 --libs` -lgdi32
|
||||
LDFLAGS := -Wl,-Bdynamic $(shell pkg-config mpv glfw3 --libs) -lgdi32 \
|
||||
-static-libgcc -static-libstdc++ -static
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
|
||||
190
Makefile.nx
Normal file
190
Makefile.nx
Normal file
@@ -0,0 +1,190 @@
|
||||
#---------------------------------------------------------------------------------
|
||||
.SUFFIXES:
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
ifeq ($(strip $(DEVKITPRO)),)
|
||||
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
|
||||
endif
|
||||
|
||||
TOPDIR ?= $(CURDIR)
|
||||
include $(DEVKITPRO)/libnx/switch_rules
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET := xplayer
|
||||
BUILD := build
|
||||
SRCS := src imgui
|
||||
DATA := data
|
||||
INCLUDES := imgui
|
||||
#ROMFS := romfs
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE
|
||||
CFLAGS := -g -Wall -O2 -ffunction-sections $(ARCH) $(DEFINES)
|
||||
CFLAGS += $(INCLUDE) -D__SWITCH__
|
||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -DIMGUI_IMPL_OPENGL_LOADER_CUSTOM
|
||||
ASFLAGS := -g $(ARCH)
|
||||
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
||||
LIBS := `$(PREFIX)pkg-config mpv --libs` \
|
||||
-lglfw3 -lEGL -lglapi -lglad -ldrm_nouveau -lm -lnx
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS := $(PORTLIBS) $(LIBNX)
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# no real need to edit anything past this point unless you need to add additional
|
||||
# rules for different file extensions
|
||||
#---------------------------------------------------------------------------------
|
||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OUTPUT := $(CURDIR)/$(TARGET)
|
||||
export TOPDIR := $(CURDIR)
|
||||
|
||||
export VPATH := $(foreach dir,$(SRCS),$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||
|
||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||
|
||||
CFILES := $(foreach dir,$(SRCS),$(notdir $(wildcard $(dir)/*.c)))
|
||||
CPPFILES := $(foreach dir,$(SRCS),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
SFILES := $(foreach dir,$(SRCS),$(notdir $(wildcard $(dir)/*.s)))
|
||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# use CXX for linking C++ projects, CC for standard C
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(CPPFILES)),)
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CC)
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CXX)
|
||||
#---------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
|
||||
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
|
||||
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
|
||||
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I$(CURDIR)/$(BUILD)
|
||||
|
||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||
|
||||
ifeq ($(strip $(CONFIG_JSON)),)
|
||||
jsons := $(wildcard *.json)
|
||||
ifneq (,$(findstring $(TARGET).json,$(jsons)))
|
||||
export APP_JSON := $(TOPDIR)/$(TARGET).json
|
||||
else
|
||||
ifneq (,$(findstring config.json,$(jsons)))
|
||||
export APP_JSON := $(TOPDIR)/config.json
|
||||
endif
|
||||
endif
|
||||
else
|
||||
export APP_JSON := $(TOPDIR)/$(CONFIG_JSON)
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(ICON)),)
|
||||
icons := $(wildcard *.jpg)
|
||||
ifneq (,$(findstring $(TARGET).jpg,$(icons)))
|
||||
export APP_ICON := $(TOPDIR)/$(TARGET).jpg
|
||||
else
|
||||
ifneq (,$(findstring icon.jpg,$(icons)))
|
||||
export APP_ICON := $(TOPDIR)/icon.jpg
|
||||
endif
|
||||
endif
|
||||
else
|
||||
export APP_ICON := $(TOPDIR)/$(ICON)
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(NO_ICON)),)
|
||||
export NROFLAGS += --icon=$(APP_ICON)
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(NO_NACP)),)
|
||||
export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp
|
||||
endif
|
||||
|
||||
ifneq ($(APP_TITLEID),)
|
||||
export NACPFLAGS += --titleid=$(APP_TITLEID)
|
||||
endif
|
||||
|
||||
ifneq ($(ROMFS),)
|
||||
export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS)
|
||||
endif
|
||||
|
||||
.PHONY: $(BUILD) clean all
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
all: $(BUILD)
|
||||
|
||||
$(BUILD):
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
clean:
|
||||
@echo clean ...
|
||||
ifeq ($(strip $(APP_JSON)),)
|
||||
@rm -fr $(BUILD) $(TARGET).nro $(TARGET).nacp $(TARGET).elf
|
||||
else
|
||||
@rm -fr $(BUILD) $(TARGET).nsp $(TARGET).nso $(TARGET).npdm $(TARGET).elf
|
||||
endif
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
.PHONY: all
|
||||
|
||||
DEPENDS := $(OFILES:.o=.d)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(APP_JSON)),)
|
||||
|
||||
all : $(OUTPUT).nro
|
||||
|
||||
ifeq ($(strip $(NO_NACP)),)
|
||||
$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp
|
||||
else
|
||||
$(OUTPUT).nro : $(OUTPUT).elf
|
||||
endif
|
||||
|
||||
else
|
||||
|
||||
all : $(OUTPUT).nsp
|
||||
|
||||
$(OUTPUT).nsp : $(OUTPUT).nso $(OUTPUT).npdm
|
||||
|
||||
$(OUTPUT).nso : $(OUTPUT).elf
|
||||
|
||||
endif
|
||||
|
||||
$(OUTPUT).elf : $(OFILES)
|
||||
|
||||
$(OFILES_SRC) : $(HFILES_BIN)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# you need a rule like this for each extension you use as binary data
|
||||
#---------------------------------------------------------------------------------
|
||||
%.bin.o %_bin.h : %.bin
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
-include $(DEPENDS)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------------
|
||||
@@ -1,4 +1,4 @@
|
||||
# xPlayer
|
||||
# xplayer
|
||||
|
||||
### Build On MSYS2
|
||||
|
||||
@@ -25,7 +25,7 @@ To build for Switch, a standard development environment must first be set up. In
|
||||
(dkp-)pacman -S switch-glfw switch-curl
|
||||
|
||||
cmake -B build -DCMAKE_TOOLCHAIN_FILE="$DEVKITPRO/cmake/Switch.cmake"
|
||||
make -C build xPlayer_nro -j$(nproc)
|
||||
make -C build xplayer_nro -j$(nproc)
|
||||
# for debug
|
||||
nxlink -a 192.168.3.97 -s build/xPlayer.nro --args https://pan.3m3m.top/api/public/dl/Cwg6sGXL
|
||||
nxlink -a 192.168.3.97 -s build/xplayer.nro --args https://pan.3m3m.top/api/public/dl/Cwg6sGXL
|
||||
```
|
||||
64
src/main.cpp
64
src/main.cpp
@@ -6,15 +6,20 @@
|
||||
|
||||
#include <imgui_impl_glfw.h>
|
||||
#include <imgui_impl_opengl3.h>
|
||||
#ifdef IMGUI_IMPL_OPENGL_ES3
|
||||
#include <GLES3/gl3.h>
|
||||
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
||||
#include <GLES2/gl2.h>
|
||||
#endif
|
||||
#if defined(__SWITCH__)
|
||||
#include <glad/glad.h>
|
||||
#elif !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
|
||||
#include <imgui_impl_opengl3_loader.h>
|
||||
#endif
|
||||
#define GLFW_INCLUDE_NONE
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#ifdef __SWITCH__
|
||||
#ifdef _WIN32
|
||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||
#include <GLFW/glfw3native.h>
|
||||
#elif defined(__SWITCH__)
|
||||
#include <switch.h>
|
||||
|
||||
extern "C" void userAppInit() {
|
||||
@@ -28,6 +33,10 @@ extern "C" void userAppExit() {
|
||||
plExit();
|
||||
socketExit();
|
||||
}
|
||||
#elif defined(__linux__)
|
||||
#define GLFW_EXPOSE_NATIVE_X11
|
||||
#define GLFW_EXPOSE_NATIVE_WAYLAND
|
||||
#include <GLFW/glfw3native.h>
|
||||
#endif
|
||||
|
||||
static void die(const char* msg) {
|
||||
@@ -35,6 +44,11 @@ static void die(const char* msg) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void glfw_error_callback(int error, const char* description)
|
||||
{
|
||||
fprintf(stderr, "GLFW Error %d: %s\n", error, description);
|
||||
}
|
||||
|
||||
static int64_t mpv_property_int(mpv_handle* mpv, const char* key) {
|
||||
int64_t value = -1;
|
||||
mpv_get_property(mpv, key, MPV_FORMAT_INT64, &value);
|
||||
@@ -45,6 +59,7 @@ static int64_t mpv_property_int(mpv_handle* mpv, const char* key) {
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc < 2) die("pass a single media file as argument");
|
||||
|
||||
glfwSetErrorCallback(glfw_error_callback);
|
||||
if (!glfwInit()) die("init glfw failed");
|
||||
|
||||
static int osdShow = 0;
|
||||
@@ -56,29 +71,34 @@ int main(int argc, char* argv[]) {
|
||||
mpv_set_option_string(mpv, "terminal", "yes");
|
||||
mpv_set_option_string(mpv, "ytdl", "no");
|
||||
mpv_set_option_string(mpv, "hwdec", "auto");
|
||||
mpv_set_option_string(mpv, "vo", "libmpv");
|
||||
#ifdef _DEBUG
|
||||
mpv_set_option_string(this->mpv, "msg-level", "all=v");
|
||||
mpv_set_option_string(mpv, "msg-level", "all=v");
|
||||
#endif
|
||||
if (mpv_initialize(mpv) < 0) die("init mpv failed");
|
||||
|
||||
#if defined(IMGUI_IMPL_OPENGL_ES3)
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
||||
const char* glsl_version = "#version 100";
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
||||
glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
|
||||
#elif defined(__APPLE__)
|
||||
const char* glsl_version = "#version 150";
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||
#elif defined(__SWITCH__)
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
#else
|
||||
const char* glsl_version = "#version 130";
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
||||
#endif
|
||||
|
||||
// Create window with graphics context
|
||||
GLFWwindow* window = glfwCreateWindow(1280, 720, argv[1], nullptr, nullptr);
|
||||
GLFWwindow* window = glfwCreateWindow(1280, 720, "xplayer", nullptr, nullptr);
|
||||
if (!window) {
|
||||
glfwTerminate();
|
||||
return -1;
|
||||
@@ -91,6 +111,8 @@ int main(int argc, char* argv[]) {
|
||||
glfwSetWindowShouldClose(window, 1);
|
||||
else if (key == GLFW_KEY_ENTER)
|
||||
osdShow = !osdShow;
|
||||
else if (key == GLFW_KEY_TAB)
|
||||
mpv_command_string(mpv, "script-binding stats/display-stats-toggle");
|
||||
else if (key == GLFW_KEY_SPACE)
|
||||
mpv_command_string(mpv, "cycle pause");
|
||||
else if (key == GLFW_KEY_LEFT)
|
||||
@@ -105,16 +127,30 @@ int main(int argc, char* argv[]) {
|
||||
printf("glfwKeyCallback key press %d\n", key);
|
||||
}
|
||||
});
|
||||
|
||||
#ifdef _WIN32
|
||||
HWND wid = glfwGetWin32Window(window);
|
||||
mpv_set_option(mpv, "wid", MPV_FORMAT_INT64, &wid);
|
||||
#endif
|
||||
glfwMakeContextCurrent(window);
|
||||
#if defined(__SWITCH__)
|
||||
// Load OpenGL routines using glad
|
||||
gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
|
||||
#endif
|
||||
glfwSwapInterval(1);
|
||||
glfwSetTime(0);
|
||||
|
||||
if (mpv_initialize(mpv) < 0) die("init mpv failed");
|
||||
mpv_opengl_init_params gl_init_params{
|
||||
[](void* fn_ctx, const char* name) { return (void*)glfwGetProcAddress(name); }, nullptr};
|
||||
mpv_render_param params[] = {
|
||||
{MPV_RENDER_PARAM_API_TYPE, const_cast<char*>(MPV_RENDER_API_TYPE_OPENGL)},
|
||||
{MPV_RENDER_PARAM_OPENGL_INIT_PARAMS, &gl_init_params},
|
||||
#if defined(GLFW_EXPOSE_NATIVE_X11)
|
||||
{MPV_RENDER_PARAM_X11_DISPLAY, glfwGetX11Display()},
|
||||
#endif
|
||||
#if defined(GLFW_EXPOSE_NATIVE_WAYLAND)
|
||||
{MPV_RENDER_PARAM_WL_DISPLAY, glfwGetWaylandDisplay()},
|
||||
#endif
|
||||
{MPV_RENDER_PARAM_INVALID, nullptr},
|
||||
};
|
||||
if (mpv_render_context_create(&mpv_context, mpv, params) < 0) die("init mpv context failed");
|
||||
@@ -139,7 +175,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
// Setup Platform/Renderer backends
|
||||
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
||||
ImGui_ImplOpenGL3_Init(nullptr);
|
||||
ImGui_ImplOpenGL3_Init(glsl_version);
|
||||
|
||||
const char* args[] = {"loadfile", argv[1], nullptr};
|
||||
if (mpv_command_async(mpv, 0, args) < 0) die("load file failed");
|
||||
|
||||
Reference in New Issue
Block a user