Make some Dreamcast OpenGL programs.
This commit is contained in:
commit
4d4582831c
9 changed files with 243 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
/.cache
|
||||
/build
|
4
.vscode/kos_environ.sh
vendored
Normal file
4
.vscode/kos_environ.sh
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
|
||||
#set the KOS environtment variables
|
||||
source /opt/toolchains/dc/kos/environ.sh
|
8
.vscode/kos_make.sh
vendored
Normal file
8
.vscode/kos_make.sh
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
#!/bin/bash
|
||||
|
||||
#set the KOS environtment variables
|
||||
source /opt/toolchains/dc/kos/environ.sh
|
||||
|
||||
make
|
||||
|
||||
exit
|
23
.vscode/settings.json
vendored
Normal file
23
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"C_Cpp.default.includePath": [
|
||||
"${workspaceFolder}/**",
|
||||
"/opt/toolchains/dc/kos/**",
|
||||
"/opt/toolchains/dc/kos-ports/**"
|
||||
],
|
||||
"C_Cpp.default.defines": [
|
||||
"_arch_dreamcast"
|
||||
],
|
||||
"C_Cpp.default.compilerPath": "/opt/toolchains/dc/sh-elf/bin/sh-elf-gcc",
|
||||
"C_Cpp.default.cStandard": "c11",
|
||||
"C_Cpp.default.cppStandard": "c++17",
|
||||
"C_Cpp.default.intelliSenseMode": "",
|
||||
|
||||
"terminal.integrated.defaultProfile.linux": "kos-bash",
|
||||
"terminal.integrated.profiles.linux": {
|
||||
"kos-bash": {
|
||||
"path": "/usr/bin/bash",
|
||||
"args": ["--init-file", "${workspaceFolder}/.vscode/kos_environ.sh" ],
|
||||
"overrideName": true
|
||||
}
|
||||
}
|
||||
}
|
17
.vscode/tasks.json
vendored
Normal file
17
.vscode/tasks.json
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "Build",
|
||||
"type": "process",
|
||||
"command": "bash",
|
||||
"args": [
|
||||
"--init-file", "${workspaceFolder}/.vscode/kos_make.sh"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
},
|
||||
]
|
||||
}
|
26
dreamcast-cross-file.txt
Normal file
26
dreamcast-cross-file.txt
Normal file
|
@ -0,0 +1,26 @@
|
|||
[binaries]
|
||||
c = 'kos-cc'
|
||||
cpp = 'kos-c++'
|
||||
ar = 'kos-ar'
|
||||
strip = 'kos-strip'
|
||||
|
||||
[properties]
|
||||
sizeof_int = 4
|
||||
sizeof_wchar_t = 4
|
||||
sizeof_void* = 4
|
||||
|
||||
alignment_char = 1
|
||||
alignment_void* = 4
|
||||
alignment_double = 4
|
||||
|
||||
has_function_printf = true
|
||||
sys_root = '/opt/toolchains/dc/sh-elf/'
|
||||
|
||||
[built-in options]
|
||||
c_args = ['-D_arch_dreamcast', '-D_arch_sub_pristine', '-ml', '-m4-single-only', '-ffunction-sections', '-fdata-sections', '-s', '-fno-builtin', '-fno-stack-protector' ]
|
||||
|
||||
[host_machine]
|
||||
system = 'dreamcast'
|
||||
cpu_family = 'sh4'
|
||||
cpu = 'sh4'
|
||||
endian = 'little'
|
85
gl.c
Normal file
85
gl.c
Normal file
|
@ -0,0 +1,85 @@
|
|||
#include <kos.h>
|
||||
#include <stdio.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#include <GL/glkos.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
float angle = 0;
|
||||
float deltaTime = 1.0/60.0;
|
||||
const float microSecond = 0.000001f;
|
||||
float speed = 5.0f;
|
||||
|
||||
void initScreen() {
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
|
||||
}
|
||||
|
||||
void displayStuff() {
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glPushMatrix();
|
||||
glRotatef(angle, 0, 0, 1);
|
||||
glColor3f(1.0f, 1.0f, 1.0f);
|
||||
glBegin(GL_POLYGON);
|
||||
glVertex3f(0.25f, 0.25f, 0.0f);
|
||||
glVertex3f(0.75f, 0.25f, 0.0f);
|
||||
glVertex3f(0.75f, 0.75f, 0.0f);
|
||||
glVertex3f(0.25f, 0.75f, 0.0f);
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
|
||||
// glFlush();
|
||||
glKosSwapBuffers();
|
||||
}
|
||||
|
||||
void process_input() {
|
||||
maple_device_t *controller;
|
||||
cont_state_t *controller_state;
|
||||
|
||||
controller = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);
|
||||
|
||||
if (controller) {
|
||||
controller_state = (cont_state_t *)maple_dev_status(controller);
|
||||
|
||||
if (!controller_state) {
|
||||
printf("An error has occured while trying to read the controller.\n");
|
||||
}
|
||||
|
||||
if (controller_state->buttons & CONT_DPAD_RIGHT) {
|
||||
speed += 1.0f;
|
||||
} else if (controller_state->buttons & CONT_DPAD_LEFT) {
|
||||
speed -= 1.0f;
|
||||
}
|
||||
|
||||
if (speed < 1.0f) {
|
||||
speed = 1.0f;
|
||||
}
|
||||
|
||||
angle += (controller_state->joyx / 127.0f) * deltaTime * speed;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
glKosInit();
|
||||
initScreen();
|
||||
printf("GL_VENDOR: %s\n", glGetString(GL_VENDOR));
|
||||
printf("GL_RENDERER: %s\n", glGetString(GL_RENDERER));
|
||||
printf("GL_VERSION: %s\n", glGetString(GL_VERSION));
|
||||
printf("GL_EXTENSIONS: %s\n", glGetString(GL_EXTENSIONS));
|
||||
struct timeval beginningOfFrame, endOfFrame;
|
||||
|
||||
while (1) {
|
||||
gettimeofday(&beginningOfFrame, 0);
|
||||
process_input();
|
||||
displayStuff();
|
||||
gettimeofday(&endOfFrame, 0);
|
||||
float time = ((float)(endOfFrame.tv_usec) * microSecond) - ((float)(beginningOfFrame.tv_usec) * microSecond);
|
||||
if (time > 0.0f) {
|
||||
deltaTime = time;
|
||||
}
|
||||
}
|
||||
}
|
50
hello.c
Normal file
50
hello.c
Normal file
|
@ -0,0 +1,50 @@
|
|||
#include <kos.h>
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#include <GL/glkos.h>
|
||||
|
||||
void triangle() {
|
||||
// glClearColor(1.0f, 1.0f, 0.0f, 0.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
glColor3f(1.0f, 0.0f, 0.0f);
|
||||
glVertex3f(-1.0f, -1.0f, 0.0f);
|
||||
|
||||
glColor3f(0.0f, 1.0f, 0.0f);
|
||||
glVertex3f(0.0f, 1.0f, 0.0f);
|
||||
|
||||
glColor3f(0.0f, 0.0f, 1.0f);
|
||||
glVertex3f(1.0f, -1.0f, 0.0f);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
maple_device_t *controller;
|
||||
|
||||
glKosInit();
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
|
||||
// gluPerspective(45.0f, 640.0f/480.0f, 0.1f, 100.0f);
|
||||
// glMatrixMode(GL_MODELVIEW);
|
||||
// glEnable(GL_TEXTURE_2D);
|
||||
// glEnable(GL_DEPTH_TEST);
|
||||
|
||||
// glFrontFace(GL_CW);
|
||||
// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
glClearColor(0.3f, 0.4f, 0.5f, 1.0f);
|
||||
|
||||
while (1) {
|
||||
// glLoadIdentity();
|
||||
// glTranslatef(-5.0f, 0.0f, 0.0f);
|
||||
// glEnable(GL_CULL_FACE);
|
||||
triangle();
|
||||
|
||||
glKosSwapBuffers();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
28
meson.build
Normal file
28
meson.build
Normal file
|
@ -0,0 +1,28 @@
|
|||
project('dreamcast-opengl', 'c')
|
||||
|
||||
cc = meson.get_compiler('c')
|
||||
|
||||
kosinc = include_directories('/opt/toolchains/dc/kos/include')
|
||||
koskernelinc = include_directories('/opt/toolchains/dc/kos/kernel/arch/dreamcast/include')
|
||||
kosaddonsinc = include_directories('/opt/toolchains/dc/kos/addons/include')
|
||||
kosportsinc = include_directories('/opt/toolchains/dc/kos-ports/include')
|
||||
|
||||
GL = cc.find_library('GL', required: true)
|
||||
math = cc.find_library('m', required: true)
|
||||
# pcx = cc.find_library('pcx', required: true)
|
||||
# kosutils = cc.find_library('kosutils', required: true)
|
||||
|
||||
deps = [
|
||||
GL,
|
||||
math
|
||||
]
|
||||
|
||||
incdirs = [
|
||||
kosinc,
|
||||
koskernelinc,
|
||||
kosaddonsinc,
|
||||
kosportsinc
|
||||
]
|
||||
|
||||
executable('hello.elf', ['hello.c'], dependencies: deps, include_directories: incdirs)
|
||||
executable('gl.elf', ['gl.c'], dependencies: deps, include_directories: incdirs)
|
Loading…
Reference in a new issue