Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mohamedLT/V_sokol_gp
a V wrapper for the sokol_gp library
https://github.com/mohamedLT/V_sokol_gp
Last synced: 3 months ago
JSON representation
a V wrapper for the sokol_gp library
- Host: GitHub
- URL: https://github.com/mohamedLT/V_sokol_gp
- Owner: mohamedLT
- License: mit
- Created: 2022-09-20T08:40:58.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2022-09-20T10:06:32.000Z (about 2 years ago)
- Last Synced: 2024-04-23T16:38:35.063Z (7 months ago)
- Language: C
- Size: 28.3 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-v - V_sokol_gp - A V wrapper for the sokol_gp library for easy and fast 2d graphics. (Libraries / Graphics)
README
# V_sokol_gp
a V wrapper for the sokol_gp library# Sokol_gp
Sokol_gp is a 2d rendering library for Sokol that has many optimations to it like batch rendering plus it is super easy to use and setup
# install
`v install mohamedLT.sokolgp`
# supported platforms
basically, it runs where Sokol runs
for android you can use vab
# Example :
```
import gg
import sokol
import sokol.sapp
import mohamedlt.sokolgp
import sokol.gfx
import mathfn frame(s voidptr) {
width := sapp.width()
height := sapp.height()
ratio := width/f32(height)sokolgp.begin(width, height)
sokolgp.viewport(0, 0, width, height)
sokolgp.project(-ratio, ratio, 1.0, -1.0)sokolgp.set_color(0.1, 0.1, 0.1, 1.0)
sokolgp.clear()time := f32(sapp.frame_count() * sapp.frame_duration())
r := math.sinf(time)*0.5+0.5
g := math.cosf(time)*0.5+0.5
sokolgp.set_color(r, g, 0.3, 1.0)
sokolgp.rotate_at(time, 0.0, 0.0)
sokolgp.draw_filled_rect(-0.5, -0.5, 1.0, 1.0)pass_action := gfx.PassAction{}
gfx.begin_default_pass(&pass_action, width, height)
sokolgp.flush()
sokolgp.end()
gfx.end_pass()
gfx.commit()
}fn init(s voidptr) {
sgdesc := sapp.create_desc()
gfx.setup(&sgdesc)
if !gfx.is_valid() {
println("Failed to create Sokol GFX context!\n")
exit(-1)
}sgpdesc := sokolgp.Desc{}
sokolgp.setup(&sgpdesc)
if !sokolgp.is_valid() {
println("Failed to create Sokol GP context: ${sokolgp.get_error_message(sokolgp.get_last_error())}\n")
exit(-1)
}
}struct App {
mut:
gg &gg.Context = unsafe { nil }
}[console]
fn main() {
mut app := &App{
gg: 0
}app.gg = gg.new_context(
width: 600
height: 600
user_data: app
create_window: true
window_title: '3D Cube Demo'
frame_fn: frame
init_fn: init
)app.gg.run()
}
```