Last active
May 20, 2019 18:18
-
-
Save radgeRayden/329dbcac3dd0daa361871bb17e9b284f to your computer and use it in GitHub Desktop.
sokol triangle example in scopes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include | |
(import sokol) | |
""""#define SOKOL_NO_ENTRY | |
#define SOKOL_IMPL | |
#define SOKOL_GLCORE33 | |
#include "include/sokol/sokol_app.h" | |
#include "include/sokol/sokol_gfx.h" | |
include | |
(import C) | |
""""#include <stdlib.h> | |
#include <stdio.h> | |
load-object (module-dir .. "/sokol.o") #so sokol can be called in an offline build | |
global gfx_bindings : sokol.sg_bindings | |
global gfx_pipeline : sokol.sg_pipeline | |
global pass_action : sokol.sg_pass_action | |
depth = | |
local sokol.sg_depth_attachment_action | |
action = sokol._SG_ACTION_DEFAULT | |
stencil = | |
local sokol.sg_stencil_attachment_action | |
action = sokol._SG_ACTION_DEFAULT | |
fragment_shader_src := | |
""""#version 330 | |
in vec4 color; | |
out vec4 frag_color; | |
void main() { | |
frag_color = color; | |
} | |
vertex_shader_src := | |
""""#version 330 | |
in vec4 position; | |
in vec4 color0; | |
out vec4 color; | |
void main() { | |
gl_Position = position; | |
color = color0; | |
} | |
fn game_init() (using sokol) | |
#sokol initialization | |
local gfx_desc : sg_desc | |
sg_setup &gfx_desc | |
local vertices = | |
arrayof f32 | |
#positions colors | |
\ 0.0 0.5 0.5 1.0 0.0 0.0 1.0 | |
\ 0.5 -0.5 0.5 0.0 1.0 0.0 1.0 | |
\ -0.5 -0.5 0.5 0.0 0.0 1.0 1.0 | |
gfx_bindings.vertex_buffers @ 0 = | |
sg_make_buffer | |
& | |
local sg_buffer_desc | |
size = (sizeof vertices) #(countof vertices) | |
type = SG_BUFFERTYPE_VERTEXBUFFER | |
usage = _SG_USAGE_DEFAULT | |
content = &vertices | |
label = "triangle-vertices" | |
local shader_desc : sg_shader_desc | |
vs = (local sg_shader_stage_desc (source = vertex_shader_src)) | |
fs = (local sg_shader_stage_desc (source = fragment_shader_src)) | |
label = "triangle-shader" | |
(. (shader_desc.attrs @ 0) name) = "position" | |
(. (shader_desc.attrs @ 0) sem_name) = "POS" | |
(. (shader_desc.attrs @ 1) name) = "color0" | |
(. (shader_desc.attrs @ 1) sem_name) = "COLOR" | |
local shader = (sg_make_shader &shader_desc) | |
local def_stencil_state : sg_stencil_state | |
fail_op = _SG_STENCILOP_DEFAULT | |
depth_fail_op = _SG_STENCILOP_DEFAULT | |
pass_op = _SG_STENCILOP_DEFAULT | |
compare_func = _SG_COMPAREFUNC_DEFAULT | |
local pip_desc : sg_pipeline_desc | |
shader = shader | |
primitive_type = _SG_PRIMITIVETYPE_DEFAULT | |
index_type = _SG_INDEXTYPE_DEFAULT | |
depth_stencil = | |
local sg_depth_stencil_state | |
stencil_front = def_stencil_state | |
stencil_back = def_stencil_state | |
depth_compare_func = _SG_COMPAREFUNC_DEFAULT | |
blend = | |
local sg_blend_state | |
src_factor_rgb = _SG_BLENDFACTOR_DEFAULT | |
dst_factor_rgb = _SG_BLENDFACTOR_DEFAULT | |
op_rgb = _SG_BLENDOP_DEFAULT | |
src_factor_alpha = _SG_BLENDFACTOR_DEFAULT | |
dst_factor_alpha = _SG_BLENDFACTOR_DEFAULT | |
op_alpha = _SG_BLENDOP_DEFAULT | |
color_format = _SG_PIXELFORMAT_DEFAULT | |
depth_format = _SG_PIXELFORMAT_DEFAULT | |
rasterizer = | |
local sg_rasterizer_state | |
cull_mode = _SG_CULLMODE_DEFAULT | |
face_winding = _SG_FACEWINDING_DEFAULT | |
label = "triangle-pipeline" | |
pip_desc.layout.attrs @ 0 = (local sg_vertex_attr_desc (format = SG_VERTEXFORMAT_FLOAT3)) | |
pip_desc.layout.attrs @ 1 = (local sg_vertex_attr_desc (format = SG_VERTEXFORMAT_FLOAT4)) | |
gfx_pipeline = (sg_make_pipeline &pip_desc) | |
pass_action.colors @ 0 = | |
local sokol.sg_color_attachment_action | |
action = sokol.SG_ACTION_CLEAR | |
val = (arrayof f32 0.0 0.0 0.0 1.0) | |
; | |
fn game_update () (using sokol) | |
sg_begin_default_pass | |
&pass_action | |
(sapp_width) | |
(sapp_height) | |
sg_apply_pipeline gfx_pipeline | |
sg_apply_bindings &gfx_bindings | |
sg_draw 0 3 1 | |
(sg_end_pass) | |
(sg_commit) | |
fn game_cleanup() | |
sokol.sg_shutdown() | |
fn game_event(event) | |
fn main(argc argv) (returning i32) | |
local app_desc : sokol.sapp_desc | |
width = 640 | |
height = 480 | |
init_cb = (static-typify game_init) | |
frame_cb = (static-typify game_update) | |
cleanup_cb = (static-typify game_cleanup) | |
event_cb = (static-typify game_event (pointer sokol.sapp_event)) | |
window_title = "game!!!!" | |
(sokol.sapp_run &app_desc) | |
return 0 | |
compile-object "main.o" | |
do | |
let main = | |
static-typify main (mutable (@ (mutable (@ i8)))) | |
let game_update = (static-typify game_update) | |
locals; | |
# (main 0 0) | |
# change this according to your environment. #works_on_my_machine | |
(C.system | |
(.. "x86_64-w64-mingw32-gcc -g " | |
\ "main.o sokol.c " | |
\ "-lkernel32 " | |
\ "-lgdi32 " | |
\ "-luser32 " | |
\ "-o game.exe ")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define SOKOL_IMPL | |
#define SOKOL_GLCORE33 | |
#define SOKOL_NO_ENTRY | |
#define SOKOL_DEBUG | |
#define SOKOL_VALIDATE_NON_FATAL | |
#include "include/sokol/sokol_app.h" | |
#include "include/sokol/sokol_gfx.h" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment