summaryrefslogtreecommitdiff
path: root/main.c3
blob: 725abd5deb1f9687a14f03e40e348cb35c379ed9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
*
* Copyright (C) 2026 andromeda
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

module main;
import std::io;
import std::os;
import rgfw;
import rsgl;
import rfont;
import libc::termios;

faultdef FAIL_OPENPTY, FAIL_FORK;

char[*] font_data = $embed("Miracode.ttf");

fn Window* init()
{
  GlHints* hints = rgfw::getGlobalHints();
  hints.major = 3;
  hints.minor = 3;
  hints.profile = GlProfile.COMPATIBILITY;
  rgfw::setGlobalHints(hints);
  return rgfw::createWindow("window title", 0, 0, 800, 400, WindowFlags.CENTER | WindowFlags.NO_RESIZE | WindowFlags.OPENGL);
}

fn int? init_tty()
{
  int master;
  int slave;
  if (openpty(&master, &slave, null, null, null) < 0) return FAIL_OPENPTY~;
  Pid_t f = fork();
  switch (f)
  {
    case -1:
      return FAIL_FORK~;
    case 0: // child
      dup2(slave, 0);
      dup2(slave, 1);
      dup2(slave, 2);
      os::exit(execvp(getenv("SHELL"), {null}));
    default: // parent
      return master;
  }
}

fn int main(String[] args)
{
  init_tty()!!;

  Window* window = init();


  rsgl::Renderer* renderer = rsgl::renderer_init(rsgl::gl::rendererProc(), &rgfw::getProcAddress);
  rsgl::renderer_viewport(renderer, rsgl::@rect(0,0,500,500));
  rsgl::renderer_updateSize(renderer, 500, 500);

  rfont::Renderer* renderer_rfont = rsgl::rfont::renderer_init(renderer);
  Font* font = rfont::font_init_data(renderer_rfont, &font_data, 60, 500, 500);

  int w;
  int h;

  while (!rgfw::window_shouldClose(window))
  {
    rgfw::pollEvents();
    rgfw::window_getSize(window, &w, &h);

    rsgl::renderer_clear(renderer, rsgl::@rgb(125,25,75));

    rsgl::renderer_viewport(renderer, rsgl::@rect(0,0,w,h));
    rfont::renderer_set_framebuffer(renderer_rfont, w, h);

    rfont::renderer_set_color(renderer_rfont, 1, 1, 1, 1);
    rfont::draw_text(renderer_rfont, font, "smth hedgehog C3 idk", 0, 10, 60);

    rsgl::renderer_render(renderer);
    rgfw::window_swapBuffers(window);
  }

  rgfw::window_close(window);

  return(0);
}

struct Winsize
{
  ushort ws_row;
  ushort ws_column;
  ushort ws_xpixel;
  ushort ws_ypixel;
}

extern fn CInt    dup2(CInt, CInt);
extern fn CInt    execvp(ZString, ZString[]);
extern fn Pid_t   fork();
extern fn ZString getenv(ZString);
extern fn CInt    openpty(CInt*, CInt*, ZString, Termios*, Winsize*);