Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to sdl3 #101

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Dependencies

- [SDL2 2.0.9+](https://www.libsdl.org/)
- [SDL3 3.0+](https://www.libsdl.org/)
- [FreeType 2.13.0+](https://freetype.org/)
- [GLEW 2.1.0+](https://glew.sourceforge.net/)

Expand Down
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
set -xe

CC="${CXX:-cc}"
PKGS="sdl2 glew freetype2"
PKGS="glew freetype2"
CFLAGS="-Wall -Wextra -std=c11 -pedantic -ggdb"
LIBS=-lm
LIBS="-lm -lSDL3"
SRC="src/main.c src/la.c src/editor.c src/file_browser.c src/free_glyph.c src/simple_renderer.c src/common.c src/lexer.c"

if [ `uname` = "Darwin" ]; then
Expand Down
6 changes: 3 additions & 3 deletions build_msvc.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
rem launch this from msvc-enabled console

set CFLAGS=/W4 /WX /std:c11 /wd4996 /wd5105 /FC /TC /Zi /nologo
set INCLUDES=/I dependencies\SDL2\include /I dependencies\GLFW\include /I dependencies\GLEW\include
set LIBS=dependencies\SDL2\lib\x64\SDL2.lib ^
dependencies\SDL2\lib\x64\SDL2main.lib ^
set INCLUDES=/I dependencies\SDL3\include /I dependencies\GLFW\include /I dependencies\GLEW\include
set LIBS=dependencies\SDL3\lib\x64\SDL3.lib ^
dependencies\SDL3\lib\x64\SDL3main.lib ^
dependencies\GLFW\lib\glfw3.lib ^
dependencies\GLEW\lib\glew32s.lib ^
opengl32.lib User32.lib Gdi32.lib Shell32.lib
Expand Down
2 changes: 1 addition & 1 deletion build_msys2_mingw64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -xe

PKGS="--static sdl2 glew freetype2"
PKGS="--static sdl3 glew freetype2"
CFLAGS="-Wall -Wextra -pedantic -ggdb -DGLEW_STATIC `pkg-config --cflags $PKGS` -Isrc -Dassert(expression)=((void)0) "
LIBS="-lm -lopengl32 `pkg-config --libs $PKGS`"
SRC="src/main.c src/la.c src/editor.c src/file_browser.c src/free_glyph.c src/simple_renderer.c src/common.c"
Expand Down
14 changes: 7 additions & 7 deletions setup_dependencies.bat
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
@echo off

curl -fsSL -o SDL2-devel-2.0.12-VC.zip https://www.libsdl.org/release/SDL2-devel-2.0.12-VC.zip
tar -xf SDL2-devel-2.0.12-VC.zip
curl -fsSL -o SDL3-devel-2.0-VC.zip https://www.libsdl.org/release/SDL3-devel-3.0-VC.zip
tar -xf SDL3-devel-2.0-VC.zip
if not exist dependencies\ mkdir dependencies\
move SDL2-2.0.12 dependencies\SDL2
del SDL2-devel-2.0.12-VC.zip
if not exist dependencies\SDL2\temp\ mkdir dependencies\SDL2\temp\
move dependencies\SDL2\include dependencies\SDL2\temp\SDL2
move dependencies\SDL2\temp dependencies\SDL2\include
move SDL3-3.0 dependencies\SDL3
del SDL3-devel-3.0-VC.zip
if not exist dependencies\SDL3\temp\ mkdir dependencies\SDL3\temp\
move dependencies\SDL3\include dependencies\SDL3\temp\SDL3
move dependencies\SDL3\temp dependencies\SDL3\include

curl -fsSL -o glfw-3.3.2.bin.WIN64.zip https://github.com/glfw/glfw/releases/download/3.3.2/glfw-3.3.2.bin.WIN64.zip
tar -xf glfw-3.3.2.bin.WIN64.zip
Expand Down
1 change: 1 addition & 0 deletions src/editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <ctype.h>
#include "./editor.h"
#include "./common.h"

Expand Down
2 changes: 1 addition & 1 deletion src/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "simple_renderer.h"
#include "lexer.h"

#include <SDL2/SDL.h>
#include <SDL3/SDL.h>

typedef struct {
size_t begin;
Expand Down
1 change: 1 addition & 0 deletions src/file_browser.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <string.h>
#include <math.h>
#include "file_browser.h"
#include "sv.h"

Expand Down
2 changes: 1 addition & 1 deletion src/file_browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "common.h"
#include "free_glyph.h"

#include <SDL2/SDL.h>
#include <SDL3/SDL.h>

typedef struct {
Files files;
Expand Down
2 changes: 1 addition & 1 deletion src/free_glyph.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <GL/glew.h>

#define GL_GLEXT_PROTOTYPES
#include <SDL2/SDL_opengl.h>
#include <SDL3/SDL_opengl.h>

#include <ft2build.h>
#include FT_FREETYPE_H
Expand Down
50 changes: 25 additions & 25 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
#include <errno.h>
#include <string.h>

#include <SDL2/SDL.h>
#include <SDL3/SDL.h>
#define GLEW_STATIC
#include <GL/glew.h>
#define GL_GLEXT_PROTOTYPES
#include <SDL2/SDL_opengl.h>
#include <SDL3/SDL_opengl.h>

#include <ft2build.h>
#include FT_FREETYPE_H
Expand Down Expand Up @@ -110,9 +110,7 @@ int main(int argc, char **argv)
return 1;
}

SDL_Window *window =
SDL_CreateWindow("ded",
0, 0,
SDL_Window *window = SDL_CreateWindow("ded",
SCREEN_WIDTH, SCREEN_HEIGHT,
SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL);
if (window == NULL) {
Expand Down Expand Up @@ -159,19 +157,21 @@ int main(int argc, char **argv)
editor.atlas = &atlas;
editor_retokenize(&editor);

SDL_StartTextInput();

bool quit = false;
bool file_browser = false;
while (!quit) {
const Uint32 start = SDL_GetTicks();
SDL_Event event = {0};
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT: {
case SDL_EVENT_QUIT: {
quit = true;
}
break;

case SDL_KEYDOWN: {
case SDL_EVENT_KEY_DOWN: {
if (file_browser) {
switch (event.key.keysym.sym) {
case SDLK_F3: {
Expand Down Expand Up @@ -234,8 +234,8 @@ int main(int argc, char **argv)
} else {
switch (event.key.keysym.sym) {
case SDLK_HOME: {
editor_update_selection(&editor, event.key.keysym.mod & KMOD_SHIFT);
if (event.key.keysym.mod & KMOD_CTRL) {
editor_update_selection(&editor, event.key.keysym.mod & SDL_KMOD_SHIFT);
if (event.key.keysym.mod & SDL_KMOD_CTRL) {
editor_move_to_begin(&editor);
} else {
editor_move_to_line_begin(&editor);
Expand All @@ -244,8 +244,8 @@ int main(int argc, char **argv)
} break;

case SDLK_END: {
editor_update_selection(&editor, event.key.keysym.mod & KMOD_SHIFT);
if (event.key.keysym.mod & KMOD_CTRL) {
editor_update_selection(&editor, event.key.keysym.mod & SDL_KMOD_SHIFT);
if (event.key.keysym.mod & SDL_KMOD_CTRL) {
editor_move_to_end(&editor);
} else {
editor_move_to_line_end(&editor);
Expand Down Expand Up @@ -299,20 +299,20 @@ int main(int argc, char **argv)
break;

case SDLK_f: {
if (event.key.keysym.mod & KMOD_CTRL) {
if (event.key.keysym.mod & SDL_KMOD_CTRL) {
editor_start_search(&editor);
}
}
break;

case SDLK_ESCAPE: {
editor_stop_search(&editor);
editor_update_selection(&editor, event.key.keysym.mod & KMOD_SHIFT);
editor_update_selection(&editor, event.key.keysym.mod & SDL_KMOD_SHIFT);
}
break;

case SDLK_a: {
if (event.key.keysym.mod & KMOD_CTRL) {
if (event.key.keysym.mod & SDL_KMOD_CTRL) {
editor.selection = true;
editor.select_begin = 0;
editor.cursor = editor.data.count;
Expand All @@ -335,22 +335,22 @@ int main(int argc, char **argv)
break;

case SDLK_c: {
if (event.key.keysym.mod & KMOD_CTRL) {
if (event.key.keysym.mod & SDL_KMOD_CTRL) {
editor_clipboard_copy(&editor);
}
}
break;

case SDLK_v: {
if (event.key.keysym.mod & KMOD_CTRL) {
if (event.key.keysym.mod & SDL_KMOD_CTRL) {
editor_clipboard_paste(&editor);
}
}
break;

case SDLK_UP: {
editor_update_selection(&editor, event.key.keysym.mod & KMOD_SHIFT);
if (event.key.keysym.mod & KMOD_CTRL) {
editor_update_selection(&editor, event.key.keysym.mod & SDL_KMOD_SHIFT);
if (event.key.keysym.mod & SDL_KMOD_CTRL) {
editor_move_paragraph_up(&editor);
} else {
editor_move_line_up(&editor);
Expand All @@ -360,8 +360,8 @@ int main(int argc, char **argv)
break;

case SDLK_DOWN: {
editor_update_selection(&editor, event.key.keysym.mod & KMOD_SHIFT);
if (event.key.keysym.mod & KMOD_CTRL) {
editor_update_selection(&editor, event.key.keysym.mod & SDL_KMOD_SHIFT);
if (event.key.keysym.mod & SDL_KMOD_CTRL) {
editor_move_paragraph_down(&editor);
} else {
editor_move_line_down(&editor);
Expand All @@ -371,8 +371,8 @@ int main(int argc, char **argv)
break;

case SDLK_LEFT: {
editor_update_selection(&editor, event.key.keysym.mod & KMOD_SHIFT);
if (event.key.keysym.mod & KMOD_CTRL) {
editor_update_selection(&editor, event.key.keysym.mod & SDL_KMOD_SHIFT);
if (event.key.keysym.mod & SDL_KMOD_CTRL) {
editor_move_word_left(&editor);
} else {
editor_move_char_left(&editor);
Expand All @@ -382,8 +382,8 @@ int main(int argc, char **argv)
break;

case SDLK_RIGHT: {
editor_update_selection(&editor, event.key.keysym.mod & KMOD_SHIFT);
if (event.key.keysym.mod & KMOD_CTRL) {
editor_update_selection(&editor, event.key.keysym.mod & SDL_KMOD_SHIFT);
if (event.key.keysym.mod & SDL_KMOD_CTRL) {
editor_move_word_right(&editor);
} else {
editor_move_char_right(&editor);
Expand All @@ -396,7 +396,7 @@ int main(int argc, char **argv)
}
break;

case SDL_TEXTINPUT: {
case SDL_EVENT_TEXT_INPUT: {
if (file_browser) {
// Nothing for now
// Once we have incremental search in the file browser this may become useful
Expand Down
2 changes: 1 addition & 1 deletion src/simple_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <GL/glew.h>

#define GL_GLEXT_PROTOTYPES
#include <SDL2/SDL_opengl.h>
#include <SDL3/SDL_opengl.h>

#include "./la.h"

Expand Down