Changed draw.odin, removed DearImgui
This commit is contained in:
+25
-21
@@ -1,10 +1,9 @@
|
||||
package edit2d
|
||||
package edit2draw
|
||||
|
||||
import "base:runtime"
|
||||
import "core:fmt"
|
||||
import "core:math"
|
||||
import "core:math/linalg"
|
||||
import im "shared:odin-imgui"
|
||||
import gl "vendor:OpenGL"
|
||||
import b2 "vendor:box2d"
|
||||
import "vendor:glfw"
|
||||
@@ -29,6 +28,10 @@ make_rgba :: proc(color : b2.HexColor, alpha : f32) -> RGBA8 {
|
||||
}
|
||||
}
|
||||
|
||||
make_hex_color :: proc(rgba: RGBA8) -> b2.HexColor {
|
||||
return b2.HexColor((u32(rgba.r) << 16) | (u32(rgba.g) << 8) | u32(rgba.b))
|
||||
}
|
||||
|
||||
|
||||
camera_reset_view :: proc(camera : ^Camera) {
|
||||
camera.center = {0, 0}
|
||||
@@ -40,6 +43,7 @@ camera_init :: proc() -> Camera {
|
||||
c : Camera = {
|
||||
width = 1920,
|
||||
height = 1080,
|
||||
zoom = 1,
|
||||
}
|
||||
camera_reset_view(&c)
|
||||
return c
|
||||
@@ -1120,7 +1124,6 @@ solid_capsules_flush :: proc(capsule : ^SolidCapsules, cam : ^Camera) {
|
||||
|
||||
for count > 0 {
|
||||
batch_count := min(count, 2048)
|
||||
//fmt.println(size_of(capsules[0]))
|
||||
|
||||
gl.BufferSubData(
|
||||
gl.ARRAY_BUFFER,
|
||||
@@ -1163,6 +1166,7 @@ SolidPolygon :: struct {
|
||||
}
|
||||
|
||||
|
||||
|
||||
solid_polygon_create :: proc(polygon : ^SolidPolygon) {
|
||||
polygon.program, _ = gl.load_shaders_source(
|
||||
#load("shaders/solid_polygons.vs"),
|
||||
@@ -1318,6 +1322,7 @@ solid_polygon_add :: proc(
|
||||
color : b2.HexColor,
|
||||
) {
|
||||
|
||||
|
||||
data : PolygonData
|
||||
|
||||
data.transform = transform
|
||||
@@ -1327,7 +1332,6 @@ solid_polygon_add :: proc(
|
||||
ps := cast([^]b2.Vec2)&data.p1
|
||||
|
||||
for i in 0 ..< count {
|
||||
//fmt.print(points[i])
|
||||
ps[i] = points[i]
|
||||
}
|
||||
|
||||
@@ -1348,18 +1352,17 @@ solid_polygon_flush :: proc(polygon : ^SolidPolygon, cam : ^Camera) {
|
||||
|
||||
gl.UseProgram(polygon.program)
|
||||
|
||||
|
||||
proj := camera_build_project_matrix(cam, 0.2)
|
||||
|
||||
gl.UniformMatrix4fv(
|
||||
polygon.uniforms["projectionMatrix"].location,
|
||||
1,
|
||||
gl.FALSE,
|
||||
&proj[0][0],
|
||||
)
|
||||
gl.Uniform1f(
|
||||
polygon.uniforms["pixelScale"].location,
|
||||
f32(cam.height) / cam.zoom,
|
||||
)
|
||||
//proj := linalg.MATRIX4F32_IDENTITY
|
||||
|
||||
gl.UniformMatrix4fv(polygon.uniforms["projectionMatrix"].location, 1, gl.FALSE, &proj[0][0])
|
||||
gl.Uniform1f(polygon.uniforms["pixelScale"].location, f32(cam.height) / cam.zoom)
|
||||
/*
|
||||
gl.UniformMatrix4fv(polygon.uniforms["projectionMatrix"].location, 1, gl.FALSE, &proj[0][0])
|
||||
gl.Uniform1f(polygon.uniforms["pixelScale"].location, 0.001)
|
||||
*/
|
||||
|
||||
gl.BindVertexArray(polygon.vao)
|
||||
|
||||
@@ -1372,12 +1375,8 @@ solid_polygon_flush :: proc(polygon : ^SolidPolygon, cam : ^Camera) {
|
||||
for count > 0 {
|
||||
batch_count := min(count, batch_size)
|
||||
|
||||
gl.BufferSubData(
|
||||
gl.ARRAY_BUFFER,
|
||||
0,
|
||||
int(batch_count * size_of(PolygonData)),
|
||||
&polygon.polygons[base],
|
||||
)
|
||||
gl.BufferSubData(gl.ARRAY_BUFFER, 0, int(batch_count * size_of(PolygonData)), &polygon.polygons[base])
|
||||
|
||||
gl.DrawArraysInstanced(gl.TRIANGLES, 0, 6, batch_count)
|
||||
|
||||
check_opengl()
|
||||
@@ -1408,7 +1407,7 @@ Draw :: struct {
|
||||
solid_capsules : SolidCapsules,
|
||||
polygons : SolidPolygon,
|
||||
drawCounters : bool,
|
||||
regular_font : im.Font,
|
||||
//regular_font : im.Font,
|
||||
frame_buffer : u32,
|
||||
}
|
||||
|
||||
@@ -1562,14 +1561,18 @@ DrawPointFcn :: proc "c" (
|
||||
|
||||
DrawString :: proc(draw : ^Draw, x, y : int, str: cstring)
|
||||
{
|
||||
/*
|
||||
draw_list := im.GetForegroundDrawList()
|
||||
im.DrawList_AddText(draw_list, {f32(x), f32(y)},im.GetColorU32(.Text), str)
|
||||
*/
|
||||
}
|
||||
|
||||
DrawStringVec :: proc(draw : ^Draw, p : b2.Vec2, str: cstring)
|
||||
{
|
||||
/*
|
||||
ps := camera_convert_world_to_screen(&draw.cam, p)
|
||||
im.DrawList_AddText(im.GetForegroundDrawList(), ps,im.GetColorU32(.Text), str)
|
||||
*/
|
||||
}
|
||||
|
||||
DrawStringFcn :: proc "c" (
|
||||
@@ -1607,6 +1610,7 @@ draw_create :: proc(draw : ^Draw, camera : ^Camera) {
|
||||
circle_create(&draw.circles)
|
||||
solid_circle_create(&draw.solid_circles)
|
||||
solid_polygon_create(&draw.polygons)
|
||||
check_opengl()
|
||||
|
||||
|
||||
bounds : b2.AABB = {{-max(f32), -max(f32)}, {max(f32), max(f32)}}
|
||||
+9
-4
@@ -8,8 +8,8 @@ import im "shared:odin-imgui"
|
||||
import "shared:odin-imgui/imgui_impl_glfw"
|
||||
import "shared:odin-imgui/imgui_impl_opengl3"
|
||||
import gl "vendor:OpenGL"
|
||||
import "core:fmt"
|
||||
import "vendor:glfw"
|
||||
import draw "shared:Edit2D/draw"
|
||||
import "core:reflect"
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import "core:reflect"
|
||||
engine_state :: struct
|
||||
{
|
||||
window : glfw.WindowHandle,
|
||||
draw : Draw,
|
||||
draw : draw.Draw,
|
||||
restart, pause : bool,
|
||||
substep_count : u32,
|
||||
|
||||
@@ -139,7 +139,7 @@ engine_init :: proc($GameType : typeid, state: ^engine_state)
|
||||
imgui_impl_glfw.InitForOpenGL(state.window, true)
|
||||
imgui_impl_opengl3.Init("#version 150")
|
||||
|
||||
state.draw.cam = camera_init()
|
||||
state.draw.cam = draw.camera_init()
|
||||
|
||||
display_w, display_h := glfw.GetFramebufferSize(state.window)
|
||||
state.draw.cam.width = display_w
|
||||
@@ -147,7 +147,7 @@ engine_init :: proc($GameType : typeid, state: ^engine_state)
|
||||
state.draw.cam.zoom = 15
|
||||
state.draw.show_ui = true
|
||||
|
||||
draw_create(&state.draw, &state.draw.cam)
|
||||
draw.draw_create(&state.draw, &state.draw.cam)
|
||||
|
||||
cbor.tag_register_type({
|
||||
marshal = proc(_: ^cbor.Tag_Implementation, e: cbor.Encoder, v: any) -> cbor.Marshal_Error {
|
||||
@@ -236,6 +236,11 @@ is_key_released :: #force_inline proc(state: ^engine_state, key : i32) -> bool{
|
||||
}
|
||||
|
||||
|
||||
draw_flush :: proc(d: ^draw.Draw)
|
||||
{
|
||||
draw.draw_flush(d)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+2
-1
@@ -4,6 +4,7 @@ import b2 "vendor:box2d"
|
||||
import im "shared:odin-imgui"
|
||||
import "vendor:glfw"
|
||||
import "base:runtime"
|
||||
import draw "./draw"
|
||||
|
||||
/*
|
||||
Handling input
|
||||
@@ -67,7 +68,7 @@ handle_entity_mode :: proc(
|
||||
interface := &game.interface
|
||||
level := &game_data.levels[game.curr_level]
|
||||
input := &state.input
|
||||
mpos := camera_convert_screen_to_world(&state.draw.cam, input.mouse)
|
||||
mpos := draw.camera_convert_screen_to_world(&state.draw.cam, input.mouse)
|
||||
|
||||
//Setlect entity
|
||||
if is_key_pressed(state, glfw.MOUSE_BUTTON_LEFT)
|
||||
|
||||
@@ -3,6 +3,7 @@ package edit2d
|
||||
import b2 "vendor:box2d"
|
||||
import im "shared:odin-imgui"
|
||||
import "core:slice"
|
||||
import draw "./draw"
|
||||
import "core:fmt"
|
||||
|
||||
|
||||
@@ -38,11 +39,11 @@ interface_body_def_editor :: proc(def: ^engine_entity_def)
|
||||
|
||||
im.SliderFloat2("Position", &def.body_def.position, -50, 50)
|
||||
|
||||
angle := RAD2DEG * b2.Rot_GetAngle(def.body_def.rotation)
|
||||
angle := draw.RAD2DEG * b2.Rot_GetAngle(def.body_def.rotation)
|
||||
|
||||
if im.SliderFloat("Rotation", &angle, 0, 359)
|
||||
{
|
||||
def.body_def.rotation = b2.MakeRot(DEG2RAD * angle)
|
||||
def.body_def.rotation = b2.MakeRot(draw.DEG2RAD * angle)
|
||||
}
|
||||
|
||||
im.SliderFloat2("Linear velocity", &def.body_def.linearVelocity, 0, 500)
|
||||
|
||||
+11
-10
@@ -3,6 +3,7 @@ package edit2d
|
||||
import "core:fmt"
|
||||
import b2 "vendor:box2d"
|
||||
import im "shared:odin-imgui"
|
||||
import draw "./draw"
|
||||
|
||||
/*
|
||||
|
||||
@@ -41,11 +42,11 @@ interface_edit_joint_common :: proc(joint_def : ^joint_common, interface: ^inter
|
||||
{
|
||||
if joint_def.entity_a in level.static_indexes{
|
||||
entity_a := interface.entity_defs[level.static_indexes[joint_def.entity_a]]
|
||||
points_add(&interface.state.draw.points, entity_a.body_def.position, 20.0, b2.HexColor.Plum)
|
||||
draw.points_add(&interface.state.draw.points, entity_a.body_def.position, 20.0, b2.HexColor.Plum)
|
||||
}
|
||||
if joint_def.entity_b in level.static_indexes{
|
||||
entity_b := interface.entity_defs[level.static_indexes[joint_def.entity_b]]
|
||||
points_add(&interface.state.draw.points, entity_b.body_def.position, 20.0, b2.HexColor.Plum)
|
||||
draw.points_add(&interface.state.draw.points, entity_b.body_def.position, 20.0, b2.HexColor.Plum)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,34 +155,34 @@ interface_edit_rev_joint_minimal :: proc(joint_def: ^b2.RevoluteJointDef)
|
||||
im.SliderFloat2("localAnchorA", &joint_def.localAnchorA, -5, 5)
|
||||
im.SliderFloat2("localAnchorB", &joint_def.localAnchorB, -5, 5)
|
||||
|
||||
reference_angle := RAD2DEG * joint_def.referenceAngle
|
||||
reference_angle := draw.RAD2DEG * joint_def.referenceAngle
|
||||
if im.SliderFloat("Reference Angle", &reference_angle, 0, 359)
|
||||
{
|
||||
joint_def.referenceAngle = DEG2RAD * reference_angle
|
||||
joint_def.referenceAngle = draw.DEG2RAD * reference_angle
|
||||
}
|
||||
|
||||
target_angle := RAD2DEG * joint_def.targetAngle
|
||||
target_angle := draw.RAD2DEG * joint_def.targetAngle
|
||||
if im.SliderFloat("Target Angle", &target_angle, 0, 359)
|
||||
{
|
||||
joint_def.targetAngle = DEG2RAD * target_angle
|
||||
joint_def.targetAngle = draw.DEG2RAD * target_angle
|
||||
}
|
||||
|
||||
im.Checkbox("Enable Spring", &joint_def.enableSpring)
|
||||
im.InputFloat("Hertz ", &joint_def.hertz)
|
||||
im.InputFloat("Damping Ratio", &joint_def.dampingRatio)
|
||||
|
||||
lower_angle := RAD2DEG * joint_def.lowerAngle
|
||||
lower_angle := draw.RAD2DEG * joint_def.lowerAngle
|
||||
|
||||
if im.SliderFloat("Lower Angle", &lower_angle, 0, 359)
|
||||
{
|
||||
joint_def.lowerAngle = DEG2RAD * lower_angle
|
||||
joint_def.lowerAngle = draw.DEG2RAD * lower_angle
|
||||
}
|
||||
|
||||
upper_angle := RAD2DEG * joint_def.upperAngle
|
||||
upper_angle := draw.RAD2DEG * joint_def.upperAngle
|
||||
|
||||
if im.SliderFloat("Upper Angle", &upper_angle, 0, 359)
|
||||
{
|
||||
joint_def.upperAngle = DEG2RAD * upper_angle
|
||||
joint_def.upperAngle = draw.DEG2RAD * upper_angle
|
||||
}
|
||||
|
||||
im.InputFloat("Max Motor Limit", &joint_def.maxMotorTorque)
|
||||
|
||||
+2
-1
@@ -9,6 +9,7 @@ import "core:time"
|
||||
import b2 "vendor:box2d"
|
||||
import "core:fmt"
|
||||
import "core:encoding/cbor"
|
||||
import draw "./draw"
|
||||
|
||||
/*
|
||||
The engine can provide helper functions so that it'll be easier to write
|
||||
@@ -35,7 +36,7 @@ engine_world :: struct {
|
||||
revolute_joint_defs : [dynamic]revolt_joint_def,
|
||||
distant_joint_defs : [dynamic]distance_joint_def,
|
||||
joints : [dynamic]b2.JointId `cbor:"-"`,
|
||||
cam : Camera,
|
||||
cam : draw.Camera,
|
||||
name : string,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user