diff --git a/assets/crate.jpg b/assets/crate.jpg new file mode 100644 index 0000000..8cc39de Binary files /dev/null and b/assets/crate.jpg differ diff --git a/assets/cube.obj b/assets/cube.obj new file mode 100644 index 0000000..92c66b3 --- /dev/null +++ b/assets/cube.obj @@ -0,0 +1,38 @@ +# Blender 4.5.0 +# www.blender.org +o Cube +v -1.000000 -1.000000 1.000000 +v -1.000000 1.000000 1.000000 +v -1.000000 -1.000000 -1.000000 +v -1.000000 1.000000 -1.000000 +v 1.000000 -1.000000 1.000000 +v 1.000000 1.000000 1.000000 +v 1.000000 -1.000000 -1.000000 +v 1.000000 1.000000 -1.000000 +vt 0.625000 0.000000 +vt 0.375000 0.250000 +vt 0.375000 0.000000 +vt 0.625000 0.250000 +vt 0.375000 0.500000 +vt 0.625000 0.500000 +vt 0.375000 0.750000 +vt 0.625000 0.750000 +vt 0.375000 1.000000 +vt 0.125000 0.750000 +vt 0.125000 0.500000 +vt 0.875000 0.500000 +vt 0.625000 1.000000 +vt 0.875000 0.750000 +s 0 +f 2/1 3/2 1/3 +f 4/4 7/5 3/2 +f 8/6 5/7 7/5 +f 6/8 1/9 5/7 +f 7/5 1/10 3/11 +f 4/12 6/8 8/6 +f 2/1 4/4 3/2 +f 4/4 8/6 7/5 +f 8/6 6/8 5/7 +f 6/8 2/13 1/9 +f 7/5 5/7 1/10 +f 4/12 2/14 6/8 diff --git a/assets/meow.png b/assets/meow.png new file mode 100644 index 0000000..efc74e3 Binary files /dev/null and b/assets/meow.png differ diff --git a/assets/monkey.obj b/assets/monkey.obj new file mode 100644 index 0000000..6b0a517 --- /dev/null +++ b/assets/monkey.obj @@ -0,0 +1,1479 @@ +# Blender 4.5.0 +# www.blender.org +mtllib monkey.mtl +o Suzanne +v 0.437500 0.164062 0.765625 +v -0.437500 0.164062 0.765625 +v 0.500000 0.093750 0.687500 +v -0.500000 0.093750 0.687500 +v 0.546875 0.054688 0.578125 +v -0.546875 0.054688 0.578125 +v 0.351562 -0.023438 0.617188 +v -0.351562 -0.023438 0.617188 +v 0.351562 0.031250 0.718750 +v -0.351562 0.031250 0.718750 +v 0.351562 0.132812 0.781250 +v -0.351562 0.132812 0.781250 +v 0.273438 0.164062 0.796875 +v -0.273438 0.164062 0.796875 +v 0.203125 0.093750 0.742188 +v -0.203125 0.093750 0.742188 +v 0.156250 0.054688 0.648438 +v -0.156250 0.054688 0.648438 +v 0.078125 0.242188 0.656250 +v -0.078125 0.242188 0.656250 +v 0.140625 0.242188 0.742188 +v -0.140625 0.242188 0.742188 +v 0.242188 0.242188 0.796875 +v -0.242188 0.242188 0.796875 +v 0.273438 0.328125 0.796875 +v -0.273438 0.328125 0.796875 +v 0.203125 0.390625 0.742188 +v -0.203125 0.390625 0.742188 +v 0.156250 0.437500 0.648438 +v -0.156250 0.437500 0.648438 +v 0.351562 0.515625 0.617188 +v -0.351562 0.515625 0.617188 +v 0.351562 0.453125 0.718750 +v -0.351562 0.453125 0.718750 +v 0.351562 0.359375 0.781250 +v -0.351562 0.359375 0.781250 +v 0.437500 0.328125 0.765625 +v -0.437500 0.328125 0.765625 +v 0.500000 0.390625 0.687500 +v -0.500000 0.390625 0.687500 +v 0.546875 0.437500 0.578125 +v -0.546875 0.437500 0.578125 +v 0.625000 0.242188 0.562500 +v -0.625000 0.242188 0.562500 +v 0.562500 0.242188 0.671875 +v -0.562500 0.242188 0.671875 +v 0.468750 0.242188 0.757812 +v -0.468750 0.242188 0.757812 +v 0.476562 0.242188 0.773438 +v -0.476562 0.242188 0.773438 +v 0.445312 0.335938 0.781250 +v -0.445312 0.335938 0.781250 +v 0.351562 0.375000 0.804688 +v -0.351562 0.375000 0.804688 +v 0.265625 0.335938 0.820312 +v -0.265625 0.335938 0.820312 +v 0.226562 0.242188 0.820312 +v -0.226562 0.242188 0.820312 +v 0.265625 0.156250 0.820312 +v -0.265625 0.156250 0.820312 +v 0.351562 0.242188 0.828125 +v -0.351562 0.242188 0.828125 +v 0.351562 0.117188 0.804688 +v -0.351562 0.117188 0.804688 +v 0.445312 0.156250 0.781250 +v -0.445312 0.156250 0.781250 +v 0.000000 0.429688 0.742188 +v 0.000000 0.351562 0.820312 +v 0.000000 -0.679688 0.734375 +v 0.000000 -0.320312 0.781250 +v 0.000000 -0.187500 0.796875 +v 0.000000 -0.773438 0.718750 +v 0.000000 0.406250 0.601562 +v 0.000000 0.570312 0.570312 +v 0.000000 0.898438 -0.546875 +v 0.000000 0.562500 -0.851562 +v 0.000000 0.070312 -0.828125 +v 0.000000 -0.382812 -0.351562 +v 0.203125 -0.187500 0.562500 +v -0.203125 -0.187500 0.562500 +v 0.312500 -0.437500 0.570312 +v -0.312500 -0.437500 0.570312 +v 0.351562 -0.695312 0.570312 +v -0.351562 -0.695312 0.570312 +v 0.367188 -0.890625 0.531250 +v -0.367188 -0.890625 0.531250 +v 0.328125 -0.945312 0.523438 +v -0.328125 -0.945312 0.523438 +v 0.179688 -0.968750 0.554688 +v -0.179688 -0.968750 0.554688 +v 0.000000 -0.984375 0.578125 +v 0.437500 -0.140625 0.531250 +v -0.437500 -0.140625 0.531250 +v 0.632812 -0.039062 0.539062 +v -0.632812 -0.039062 0.539062 +v 0.828125 0.148438 0.445312 +v -0.828125 0.148438 0.445312 +v 0.859375 0.429688 0.593750 +v -0.859375 0.429688 0.593750 +v 0.710938 0.484375 0.625000 +v -0.710938 0.484375 0.625000 +v 0.492188 0.601562 0.687500 +v -0.492188 0.601562 0.687500 +v 0.320312 0.757812 0.734375 +v -0.320312 0.757812 0.734375 +v 0.156250 0.718750 0.757812 +v -0.156250 0.718750 0.757812 +v 0.062500 0.492188 0.750000 +v -0.062500 0.492188 0.750000 +v 0.164062 0.414062 0.773438 +v -0.164062 0.414062 0.773438 +v 0.125000 0.304688 0.765625 +v -0.125000 0.304688 0.765625 +v 0.203125 0.093750 0.742188 +v -0.203125 0.093750 0.742188 +v 0.375000 0.015625 0.703125 +v -0.375000 0.015625 0.703125 +v 0.492188 0.062500 0.671875 +v -0.492188 0.062500 0.671875 +v 0.625000 0.187500 0.648438 +v -0.625000 0.187500 0.648438 +v 0.640625 0.296875 0.648438 +v -0.640625 0.296875 0.648438 +v 0.601562 0.375000 0.664062 +v -0.601562 0.375000 0.664062 +v 0.429688 0.437500 0.718750 +v -0.429688 0.437500 0.718750 +v 0.250000 0.468750 0.757812 +v -0.250000 0.468750 0.757812 +v 0.000000 -0.765625 0.734375 +v 0.109375 -0.718750 0.734375 +v -0.109375 -0.718750 0.734375 +v 0.117188 -0.835938 0.710938 +v -0.117188 -0.835938 0.710938 +v 0.062500 -0.882812 0.695312 +v -0.062500 -0.882812 0.695312 +v 0.000000 -0.890625 0.687500 +v 0.000000 -0.195312 0.750000 +v 0.000000 -0.140625 0.742188 +v 0.101562 -0.148438 0.742188 +v -0.101562 -0.148438 0.742188 +v 0.125000 -0.226562 0.750000 +v -0.125000 -0.226562 0.750000 +v 0.085938 -0.289062 0.742188 +v -0.085938 -0.289062 0.742188 +v 0.398438 -0.046875 0.671875 +v -0.398438 -0.046875 0.671875 +v 0.617188 0.054688 0.625000 +v -0.617188 0.054688 0.625000 +v 0.726562 0.203125 0.601562 +v -0.726562 0.203125 0.601562 +v 0.742188 0.375000 0.656250 +v -0.742188 0.375000 0.656250 +v 0.687500 0.414062 0.726562 +v -0.687500 0.414062 0.726562 +v 0.437500 0.546875 0.796875 +v -0.437500 0.546875 0.796875 +v 0.312500 0.640625 0.835938 +v -0.312500 0.640625 0.835938 +v 0.203125 0.617188 0.851562 +v -0.203125 0.617188 0.851562 +v 0.101562 0.429688 0.843750 +v -0.101562 0.429688 0.843750 +v 0.125000 -0.101562 0.812500 +v -0.125000 -0.101562 0.812500 +v 0.210938 -0.445312 0.710938 +v -0.210938 -0.445312 0.710938 +v 0.250000 -0.703125 0.687500 +v -0.250000 -0.703125 0.687500 +v 0.265625 -0.820312 0.664062 +v -0.265625 -0.820312 0.664062 +v 0.234375 -0.914062 0.632812 +v -0.234375 -0.914062 0.632812 +v 0.164062 -0.929688 0.632812 +v -0.164062 -0.929688 0.632812 +v 0.000000 -0.945312 0.640625 +v 0.000000 0.046875 0.726562 +v 0.000000 0.210938 0.765625 +v 0.328125 0.476562 0.742188 +v -0.328125 0.476562 0.742188 +v 0.164062 0.140625 0.750000 +v -0.164062 0.140625 0.750000 +v 0.132812 0.210938 0.757812 +v -0.132812 0.210938 0.757812 +v 0.117188 -0.687500 0.734375 +v -0.117188 -0.687500 0.734375 +v 0.078125 -0.445312 0.750000 +v -0.078125 -0.445312 0.750000 +v 0.000000 -0.445312 0.750000 +v 0.000000 -0.328125 0.742188 +v 0.093750 -0.273438 0.781250 +v -0.093750 -0.273438 0.781250 +v 0.132812 -0.226562 0.796875 +v -0.132812 -0.226562 0.796875 +v 0.109375 -0.132812 0.781250 +v -0.109375 -0.132812 0.781250 +v 0.039062 -0.125000 0.781250 +v -0.039062 -0.125000 0.781250 +v 0.000000 -0.203125 0.828125 +v 0.046875 -0.148438 0.812500 +v -0.046875 -0.148438 0.812500 +v 0.093750 -0.156250 0.812500 +v -0.093750 -0.156250 0.812500 +v 0.109375 -0.226562 0.828125 +v -0.109375 -0.226562 0.828125 +v 0.078125 -0.250000 0.804688 +v -0.078125 -0.250000 0.804688 +v 0.000000 -0.289062 0.804688 +v 0.257812 -0.312500 0.554688 +v -0.257812 -0.312500 0.554688 +v 0.164062 -0.242188 0.710938 +v -0.164062 -0.242188 0.710938 +v 0.179688 -0.312500 0.710938 +v -0.179688 -0.312500 0.710938 +v 0.234375 -0.250000 0.554688 +v -0.234375 -0.250000 0.554688 +v 0.000000 -0.875000 0.687500 +v 0.046875 -0.867188 0.687500 +v -0.046875 -0.867188 0.687500 +v 0.093750 -0.820312 0.710938 +v -0.093750 -0.820312 0.710938 +v 0.093750 -0.742188 0.726562 +v -0.093750 -0.742188 0.726562 +v 0.000000 -0.781250 0.656250 +v 0.093750 -0.750000 0.664062 +v -0.093750 -0.750000 0.664062 +v 0.093750 -0.812500 0.640625 +v -0.093750 -0.812500 0.640625 +v 0.046875 -0.851562 0.632812 +v -0.046875 -0.851562 0.632812 +v 0.000000 -0.859375 0.632812 +v 0.171875 0.218750 0.781250 +v -0.171875 0.218750 0.781250 +v 0.187500 0.156250 0.773438 +v -0.187500 0.156250 0.773438 +v 0.335938 0.429688 0.757812 +v -0.335938 0.429688 0.757812 +v 0.273438 0.421875 0.773438 +v -0.273438 0.421875 0.773438 +v 0.421875 0.398438 0.773438 +v -0.421875 0.398438 0.773438 +v 0.562500 0.351562 0.695312 +v -0.562500 0.351562 0.695312 +v 0.585938 0.289062 0.687500 +v -0.585938 0.289062 0.687500 +v 0.578125 0.195312 0.679688 +v -0.578125 0.195312 0.679688 +v 0.476562 0.101562 0.718750 +v -0.476562 0.101562 0.718750 +v 0.375000 0.062500 0.742188 +v -0.375000 0.062500 0.742188 +v 0.226562 0.109375 0.781250 +v -0.226562 0.109375 0.781250 +v 0.179688 0.296875 0.781250 +v -0.179688 0.296875 0.781250 +v 0.210938 0.375000 0.781250 +v -0.210938 0.375000 0.781250 +v 0.234375 0.359375 0.757812 +v -0.234375 0.359375 0.757812 +v 0.195312 0.296875 0.757812 +v -0.195312 0.296875 0.757812 +v 0.242188 0.125000 0.757812 +v -0.242188 0.125000 0.757812 +v 0.375000 0.085938 0.726562 +v -0.375000 0.085938 0.726562 +v 0.460938 0.117188 0.703125 +v -0.460938 0.117188 0.703125 +v 0.546875 0.210938 0.671875 +v -0.546875 0.210938 0.671875 +v 0.554688 0.281250 0.671875 +v -0.554688 0.281250 0.671875 +v 0.531250 0.335938 0.679688 +v -0.531250 0.335938 0.679688 +v 0.414062 0.390625 0.750000 +v -0.414062 0.390625 0.750000 +v 0.281250 0.398438 0.765625 +v -0.281250 0.398438 0.765625 +v 0.335938 0.406250 0.750000 +v -0.335938 0.406250 0.750000 +v 0.203125 0.171875 0.750000 +v -0.203125 0.171875 0.750000 +v 0.195312 0.226562 0.750000 +v -0.195312 0.226562 0.750000 +v 0.109375 0.460938 0.609375 +v -0.109375 0.460938 0.609375 +v 0.195312 0.664062 0.617188 +v -0.195312 0.664062 0.617188 +v 0.335938 0.687500 0.593750 +v -0.335938 0.687500 0.593750 +v 0.484375 0.554688 0.554688 +v -0.484375 0.554688 0.554688 +v 0.679688 0.453125 0.492188 +v -0.679688 0.453125 0.492188 +v 0.796875 0.406250 0.460938 +v -0.796875 0.406250 0.460938 +v 0.773438 0.164062 0.375000 +v -0.773438 0.164062 0.375000 +v 0.601562 0.000000 0.414062 +v -0.601562 0.000000 0.414062 +v 0.437500 -0.093750 0.468750 +v -0.437500 -0.093750 0.468750 +v 0.000000 0.898438 0.289062 +v 0.000000 0.984375 -0.078125 +v 0.000000 -0.195312 -0.671875 +v 0.000000 -0.460938 0.187500 +v 0.000000 -0.976562 0.460938 +v 0.000000 -0.804688 0.343750 +v 0.000000 -0.570312 0.320312 +v 0.000000 -0.484375 0.281250 +v 0.851562 0.234375 0.054688 +v -0.851562 0.234375 0.054688 +v 0.859375 0.320312 -0.046875 +v -0.859375 0.320312 -0.046875 +v 0.773438 0.265625 -0.437500 +v -0.773438 0.265625 -0.437500 +v 0.460938 0.437500 -0.703125 +v -0.460938 0.437500 -0.703125 +v 0.734375 -0.046875 0.070312 +v -0.734375 -0.046875 0.070312 +v 0.593750 -0.125000 -0.164062 +v -0.593750 -0.125000 -0.164062 +v 0.640625 -0.007812 -0.429688 +v -0.640625 -0.007812 -0.429688 +v 0.335938 0.054688 -0.664062 +v -0.335938 0.054688 -0.664062 +v 0.234375 -0.351562 0.406250 +v -0.234375 -0.351562 0.406250 +v 0.179688 -0.414062 0.257812 +v -0.179688 -0.414062 0.257812 +v 0.289062 -0.710938 0.382812 +v -0.289062 -0.710938 0.382812 +v 0.250000 -0.500000 0.390625 +v -0.250000 -0.500000 0.390625 +v 0.328125 -0.914062 0.398438 +v -0.328125 -0.914062 0.398438 +v 0.140625 -0.757812 0.367188 +v -0.140625 -0.757812 0.367188 +v 0.125000 -0.539062 0.359375 +v -0.125000 -0.539062 0.359375 +v 0.164062 -0.945312 0.437500 +v -0.164062 -0.945312 0.437500 +v 0.218750 -0.281250 0.429688 +v -0.218750 -0.281250 0.429688 +v 0.210938 -0.226562 0.468750 +v -0.210938 -0.226562 0.468750 +v 0.203125 -0.171875 0.500000 +v -0.203125 -0.171875 0.500000 +v 0.210938 -0.390625 0.164062 +v -0.210938 -0.390625 0.164062 +v 0.296875 -0.312500 -0.265625 +v -0.296875 -0.312500 -0.265625 +v 0.343750 -0.148438 -0.539062 +v -0.343750 -0.148438 -0.539062 +v 0.453125 0.867188 -0.382812 +v -0.453125 0.867188 -0.382812 +v 0.453125 0.929688 -0.070312 +v -0.453125 0.929688 -0.070312 +v 0.453125 0.851562 0.234375 +v -0.453125 0.851562 0.234375 +v 0.460938 0.523438 0.429688 +v -0.460938 0.523438 0.429688 +v 0.726562 0.406250 0.335938 +v -0.726562 0.406250 0.335938 +v 0.632812 0.453125 0.281250 +v -0.632812 0.453125 0.281250 +v 0.640625 0.703125 0.054688 +v -0.640625 0.703125 0.054688 +v 0.796875 0.562500 0.125000 +v -0.796875 0.562500 0.125000 +v 0.796875 0.617188 -0.117188 +v -0.796875 0.617188 -0.117188 +v 0.640625 0.750000 -0.195312 +v -0.640625 0.750000 -0.195312 +v 0.640625 0.679688 -0.445312 +v -0.640625 0.679688 -0.445312 +v 0.796875 0.539062 -0.359375 +v -0.796875 0.539062 -0.359375 +v 0.617188 0.328125 -0.585938 +v -0.617188 0.328125 -0.585938 +v 0.484375 0.023438 -0.546875 +v -0.484375 0.023438 -0.546875 +v 0.820312 0.328125 -0.203125 +v -0.820312 0.328125 -0.203125 +v 0.406250 -0.171875 0.148438 +v -0.406250 -0.171875 0.148438 +v 0.429688 -0.195312 -0.210938 +v -0.429688 -0.195312 -0.210938 +v 0.890625 0.406250 -0.234375 +v -0.890625 0.406250 -0.234375 +v 0.773438 -0.140625 -0.125000 +v -0.773438 -0.140625 -0.125000 +v 1.039062 -0.101562 -0.328125 +v -1.039062 -0.101562 -0.328125 +v 1.281250 0.054688 -0.429688 +v -1.281250 0.054688 -0.429688 +v 1.351562 0.320312 -0.421875 +v -1.351562 0.320312 -0.421875 +v 1.234375 0.507812 -0.421875 +v -1.234375 0.507812 -0.421875 +v 1.023438 0.476562 -0.312500 +v -1.023438 0.476562 -0.312500 +v 1.015625 0.414062 -0.289062 +v -1.015625 0.414062 -0.289062 +v 1.187500 0.437500 -0.390625 +v -1.187500 0.437500 -0.390625 +v 1.265625 0.289062 -0.406250 +v -1.265625 0.289062 -0.406250 +v 1.210938 0.078125 -0.406250 +v -1.210938 0.078125 -0.406250 +v 1.031250 -0.039062 -0.304688 +v -1.031250 -0.039062 -0.304688 +v 0.828125 -0.070312 -0.132812 +v -0.828125 -0.070312 -0.132812 +v 0.921875 0.359375 -0.218750 +v -0.921875 0.359375 -0.218750 +v 0.945312 0.304688 -0.289062 +v -0.945312 0.304688 -0.289062 +v 0.882812 -0.023438 -0.210938 +v -0.882812 -0.023438 -0.210938 +v 1.039062 0.000000 -0.367188 +v -1.039062 0.000000 -0.367188 +v 1.187500 0.093750 -0.445312 +v -1.187500 0.093750 -0.445312 +v 1.234375 0.250000 -0.445312 +v -1.234375 0.250000 -0.445312 +v 1.171875 0.359375 -0.437500 +v -1.171875 0.359375 -0.437500 +v 1.023438 0.343750 -0.359375 +v -1.023438 0.343750 -0.359375 +v 0.843750 0.289062 -0.210938 +v -0.843750 0.289062 -0.210938 +v 0.835938 0.171875 -0.273438 +v -0.835938 0.171875 -0.273438 +v 0.757812 0.093750 -0.273438 +v -0.757812 0.093750 -0.273438 +v 0.820312 0.085938 -0.273438 +v -0.820312 0.085938 -0.273438 +v 0.843750 0.015625 -0.273438 +v -0.843750 0.015625 -0.273438 +v 0.812500 -0.015625 -0.273438 +v -0.812500 -0.015625 -0.273438 +v 0.726562 0.000000 -0.070312 +v -0.726562 0.000000 -0.070312 +v 0.718750 -0.023438 -0.171875 +v -0.718750 -0.023438 -0.171875 +v 0.718750 0.039062 -0.187500 +v -0.718750 0.039062 -0.187500 +v 0.796875 0.203125 -0.210938 +v -0.796875 0.203125 -0.210938 +v 0.890625 0.242188 -0.265625 +v -0.890625 0.242188 -0.265625 +v 0.890625 0.234375 -0.320312 +v -0.890625 0.234375 -0.320312 +v 0.812500 -0.015625 -0.320312 +v -0.812500 -0.015625 -0.320312 +v 0.851562 0.015625 -0.320312 +v -0.851562 0.015625 -0.320312 +v 0.828125 0.078125 -0.320312 +v -0.828125 0.078125 -0.320312 +v 0.765625 0.093750 -0.320312 +v -0.765625 0.093750 -0.320312 +v 0.843750 0.171875 -0.320312 +v -0.843750 0.171875 -0.320312 +v 1.039062 0.328125 -0.414062 +v -1.039062 0.328125 -0.414062 +v 1.187500 0.343750 -0.484375 +v -1.187500 0.343750 -0.484375 +v 1.257812 0.242188 -0.492188 +v -1.257812 0.242188 -0.492188 +v 1.210938 0.085938 -0.484375 +v -1.210938 0.085938 -0.484375 +v 1.046875 0.000000 -0.421875 +v -1.046875 0.000000 -0.421875 +v 0.882812 -0.015625 -0.265625 +v -0.882812 -0.015625 -0.265625 +v 0.953125 0.289062 -0.343750 +v -0.953125 0.289062 -0.343750 +v 0.890625 0.109375 -0.328125 +v -0.890625 0.109375 -0.328125 +v 0.937500 0.062500 -0.335938 +v -0.937500 0.062500 -0.335938 +v 1.000000 0.125000 -0.367188 +v -1.000000 0.125000 -0.367188 +v 0.960938 0.171875 -0.351562 +v -0.960938 0.171875 -0.351562 +v 1.015625 0.234375 -0.375000 +v -1.015625 0.234375 -0.375000 +v 1.054688 0.187500 -0.382812 +v -1.054688 0.187500 -0.382812 +v 1.109375 0.210938 -0.390625 +v -1.109375 0.210938 -0.390625 +v 1.085938 0.273438 -0.390625 +v -1.085938 0.273438 -0.390625 +v 1.023438 0.437500 -0.484375 +v -1.023438 0.437500 -0.484375 +v 1.250000 0.468750 -0.546875 +v -1.250000 0.468750 -0.546875 +v 1.367188 0.296875 -0.500000 +v -1.367188 0.296875 -0.500000 +v 1.312500 0.054688 -0.531250 +v -1.312500 0.054688 -0.531250 +v 1.039062 -0.085938 -0.492188 +v -1.039062 -0.085938 -0.492188 +v 0.789062 -0.125000 -0.328125 +v -0.789062 -0.125000 -0.328125 +v 0.859375 0.382812 -0.382812 +v -0.859375 0.382812 -0.382812 +s 0 +f 47 3 45 +f 4 48 46 +f 45 5 43 +f 6 46 44 +f 3 7 5 +f 8 4 6 +f 1 9 3 +f 10 2 4 +f 11 15 9 +f 16 12 10 +f 9 17 7 +f 18 10 8 +f 21 17 15 +f 22 18 20 +f 13 21 15 +f 22 14 16 +f 23 27 21 +f 28 24 22 +f 27 19 21 +f 28 20 30 +f 33 29 27 +f 34 30 32 +f 35 27 25 +f 36 28 34 +f 37 33 35 +f 38 34 40 +f 39 31 33 +f 40 32 42 +f 45 41 39 +f 46 42 44 +f 47 39 37 +f 48 40 46 +f 37 49 47 +f 38 50 52 +f 35 51 37 +f 36 52 54 +f 25 53 35 +f 26 54 56 +f 23 55 25 +f 24 56 58 +f 23 59 57 +f 60 24 58 +f 13 63 59 +f 64 14 60 +f 11 65 63 +f 66 12 64 +f 1 49 65 +f 50 2 66 +f 61 65 49 +f 50 66 62 +f 63 65 61 +f 62 66 64 +f 61 59 63 +f 64 60 62 +f 61 57 59 +f 60 58 62 +f 61 55 57 +f 58 56 62 +f 61 53 55 +f 56 54 62 +f 61 51 53 +f 54 52 62 +f 61 49 51 +f 52 50 62 +f 174 91 89 +f 175 91 176 +f 172 89 87 +f 173 90 175 +f 85 172 87 +f 173 86 88 +f 83 170 85 +f 171 84 86 +f 81 168 83 +f 169 82 84 +f 79 146 164 +f 147 80 165 +f 94 146 92 +f 95 147 149 +f 94 150 148 +f 151 95 149 +f 98 150 96 +f 99 151 153 +f 100 152 98 +f 101 153 155 +f 102 154 100 +f 103 155 157 +f 102 158 156 +f 159 103 157 +f 106 158 104 +f 107 159 161 +f 108 160 106 +f 109 161 163 +f 67 162 108 +f 67 163 68 +f 128 162 110 +f 129 163 161 +f 128 158 160 +f 159 129 161 +f 156 179 126 +f 157 180 159 +f 154 126 124 +f 155 127 157 +f 152 124 122 +f 153 125 155 +f 150 122 120 +f 151 123 153 +f 148 120 118 +f 149 121 151 +f 146 118 116 +f 147 119 149 +f 164 116 114 +f 165 117 147 +f 114 177 164 +f 177 115 165 +f 162 112 110 +f 163 113 68 +f 112 178 183 +f 178 113 184 +f 181 178 177 +f 182 178 184 +f 135 176 174 +f 176 136 175 +f 133 174 172 +f 175 134 173 +f 133 170 131 +f 134 171 173 +f 166 185 168 +f 186 167 169 +f 131 168 185 +f 169 132 186 +f 190 187 144 +f 190 188 189 +f 187 69 185 +f 188 69 189 +f 131 69 130 +f 132 69 186 +f 142 191 144 +f 192 143 145 +f 140 193 142 +f 194 141 143 +f 197 140 139 +f 198 141 196 +f 71 139 138 +f 71 139 198 +f 144 70 190 +f 145 70 192 +f 191 208 70 +f 192 208 207 +f 71 200 197 +f 201 71 198 +f 197 202 195 +f 203 198 196 +f 202 193 195 +f 203 194 205 +f 193 206 191 +f 207 194 192 +f 204 200 199 +f 205 201 203 +f 199 206 204 +f 207 199 205 +f 139 164 177 +f 165 139 177 +f 140 211 164 +f 212 141 165 +f 144 211 142 +f 145 212 214 +f 187 213 144 +f 188 214 167 +f 209 166 81 +f 210 167 214 +f 215 213 209 +f 216 214 212 +f 79 211 215 +f 212 80 216 +f 130 222 131 +f 130 223 72 +f 133 222 220 +f 223 134 221 +f 135 220 218 +f 221 136 219 +f 137 218 217 +f 219 137 217 +f 218 231 217 +f 219 231 230 +f 218 227 229 +f 228 219 230 +f 220 225 227 +f 226 221 228 +f 72 225 222 +f 72 226 224 +f 224 229 225 +f 230 224 226 +f 225 229 227 +f 228 230 226 +f 183 234 232 +f 235 184 233 +f 112 232 254 +f 233 113 255 +f 112 256 110 +f 113 257 255 +f 114 234 181 +f 115 235 253 +f 114 250 252 +f 251 115 253 +f 116 248 250 +f 249 117 251 +f 118 246 248 +f 247 119 249 +f 120 244 246 +f 245 121 247 +f 124 244 122 +f 125 245 243 +f 126 242 124 +f 127 243 241 +f 126 236 240 +f 237 127 241 +f 179 238 236 +f 239 180 237 +f 128 256 238 +f 257 129 239 +f 256 276 238 +f 257 277 259 +f 236 276 278 +f 277 237 279 +f 236 274 240 +f 237 275 279 +f 240 272 242 +f 241 273 275 +f 244 272 270 +f 273 245 271 +f 244 268 246 +f 245 269 271 +f 248 268 266 +f 269 249 267 +f 248 264 250 +f 249 265 267 +f 250 262 252 +f 251 263 265 +f 234 262 280 +f 263 235 281 +f 256 260 258 +f 261 257 259 +f 254 282 260 +f 283 255 261 +f 232 280 282 +f 281 233 283 +f 67 284 73 +f 285 67 73 +f 108 286 284 +f 287 109 285 +f 104 286 106 +f 105 287 289 +f 102 288 104 +f 103 289 291 +f 100 290 102 +f 101 291 293 +f 100 294 292 +f 295 101 293 +f 96 294 98 +f 97 295 297 +f 96 298 296 +f 299 97 297 +f 94 300 298 +f 301 95 299 +f 309 338 308 +f 309 339 329 +f 308 336 307 +f 308 337 339 +f 307 340 306 +f 307 341 337 +f 89 306 340 +f 306 90 341 +f 87 340 334 +f 341 88 335 +f 85 334 330 +f 335 86 331 +f 83 330 332 +f 331 84 333 +f 330 338 332 +f 339 331 333 +f 334 336 330 +f 335 337 341 +f 332 328 326 +f 333 329 339 +f 81 332 326 +f 333 82 327 +f 342 215 209 +f 343 216 345 +f 326 209 81 +f 327 210 343 +f 215 346 79 +f 216 347 345 +f 346 92 79 +f 347 93 301 +f 324 304 77 +f 325 304 353 +f 352 78 304 +f 353 78 351 +f 78 348 305 +f 349 78 305 +f 305 328 309 +f 329 305 309 +f 328 342 326 +f 329 343 349 +f 296 318 310 +f 319 297 311 +f 316 77 76 +f 317 77 325 +f 358 303 302 +f 359 303 357 +f 303 354 75 +f 355 303 75 +f 75 316 76 +f 317 75 76 +f 292 362 364 +f 363 293 365 +f 364 368 366 +f 369 365 367 +f 366 370 372 +f 371 367 373 +f 372 376 374 +f 377 373 375 +f 378 376 314 +f 379 377 375 +f 316 374 378 +f 375 317 379 +f 354 372 374 +f 373 355 375 +f 356 366 372 +f 367 357 373 +f 358 364 366 +f 365 359 367 +f 292 360 290 +f 293 361 365 +f 360 302 74 +f 361 302 359 +f 284 288 290 +f 289 285 291 +f 284 360 74 +f 361 285 74 +f 73 284 74 +f 74 285 73 +f 296 362 294 +f 297 363 311 +f 310 368 362 +f 369 311 363 +f 312 370 368 +f 371 313 369 +f 376 382 314 +f 377 383 371 +f 350 384 348 +f 351 385 387 +f 384 320 318 +f 385 321 387 +f 298 384 318 +f 385 299 319 +f 300 342 384 +f 343 301 385 +f 342 348 384 +f 385 349 343 +f 300 346 344 +f 345 347 301 +f 322 378 314 +f 323 379 381 +f 378 324 316 +f 379 325 381 +f 386 322 320 +f 387 323 381 +f 352 386 350 +f 353 387 381 +f 324 380 352 +f 353 381 325 +f 388 402 400 +f 389 403 415 +f 400 404 398 +f 405 401 399 +f 404 396 398 +f 405 397 407 +f 406 394 396 +f 407 395 409 +f 408 392 394 +f 409 393 411 +f 392 412 390 +f 413 393 391 +f 410 418 412 +f 419 411 413 +f 408 420 410 +f 421 409 411 +f 424 408 406 +f 425 409 423 +f 426 406 404 +f 427 407 425 +f 428 404 402 +f 429 405 427 +f 402 416 428 +f 417 403 429 +f 320 442 318 +f 321 443 445 +f 390 444 320 +f 391 445 413 +f 310 442 312 +f 443 311 313 +f 382 414 388 +f 415 383 389 +f 412 440 444 +f 441 413 445 +f 446 440 438 +f 447 441 445 +f 434 438 436 +f 439 435 437 +f 448 434 432 +f 449 435 447 +f 448 450 430 +f 449 451 433 +f 430 416 414 +f 431 417 451 +f 312 430 382 +f 431 313 383 +f 442 448 312 +f 443 449 447 +f 442 444 446 +f 447 445 443 +f 416 452 476 +f 453 417 477 +f 432 452 450 +f 433 453 463 +f 432 460 462 +f 461 433 463 +f 436 460 434 +f 437 461 459 +f 438 458 436 +f 439 459 457 +f 438 454 456 +f 455 439 457 +f 440 474 454 +f 475 441 455 +f 428 476 464 +f 477 429 465 +f 426 464 466 +f 465 427 467 +f 424 466 468 +f 467 425 469 +f 424 470 422 +f 425 471 469 +f 422 472 420 +f 423 473 471 +f 420 474 418 +f 421 475 473 +f 456 478 458 +f 457 479 481 +f 480 484 478 +f 481 485 483 +f 484 488 486 +f 489 485 487 +f 488 492 486 +f 489 493 491 +f 464 486 492 +f 487 465 493 +f 484 476 452 +f 485 477 487 +f 462 484 452 +f 463 485 479 +f 458 462 460 +f 463 459 461 +f 474 456 454 +f 475 457 481 +f 472 480 474 +f 481 473 475 +f 488 472 470 +f 489 473 483 +f 490 470 468 +f 491 471 489 +f 466 490 468 +f 491 467 469 +f 464 492 466 +f 467 493 465 +f 392 504 502 +f 505 393 503 +f 394 502 500 +f 503 395 501 +f 394 498 396 +f 395 499 501 +f 396 496 398 +f 397 497 499 +f 398 494 400 +f 399 495 497 +f 400 506 388 +f 401 507 495 +f 502 506 494 +f 503 507 505 +f 494 500 502 +f 501 495 503 +f 496 498 500 +f 501 499 497 +f 382 506 314 +f 383 507 389 +f 314 504 322 +f 505 315 323 +f 320 504 390 +f 505 321 391 +f 47 1 3 +f 4 2 48 +f 45 3 5 +f 6 4 46 +f 3 9 7 +f 8 10 4 +f 1 11 9 +f 10 12 2 +f 11 13 15 +f 16 14 12 +f 9 15 17 +f 18 16 10 +f 21 19 17 +f 22 16 18 +f 13 23 21 +f 22 24 14 +f 23 25 27 +f 28 26 24 +f 27 29 19 +f 28 22 20 +f 33 31 29 +f 34 28 30 +f 35 33 27 +f 36 26 28 +f 37 39 33 +f 38 36 34 +f 39 41 31 +f 40 34 32 +f 45 43 41 +f 46 40 42 +f 47 45 39 +f 48 38 40 +f 37 51 49 +f 38 48 50 +f 35 53 51 +f 36 38 52 +f 25 55 53 +f 26 36 54 +f 23 57 55 +f 24 26 56 +f 23 13 59 +f 60 14 24 +f 13 11 63 +f 64 12 14 +f 11 1 65 +f 66 2 12 +f 1 47 49 +f 50 48 2 +f 174 176 91 +f 175 90 91 +f 172 174 89 +f 173 88 90 +f 85 170 172 +f 173 171 86 +f 83 168 170 +f 171 169 84 +f 81 166 168 +f 169 167 82 +f 79 92 146 +f 147 93 80 +f 94 148 146 +f 95 93 147 +f 94 96 150 +f 151 97 95 +f 98 152 150 +f 99 97 151 +f 100 154 152 +f 101 99 153 +f 102 156 154 +f 103 101 155 +f 102 104 158 +f 159 105 103 +f 106 160 158 +f 107 105 159 +f 108 162 160 +f 109 107 161 +f 67 68 162 +f 67 109 163 +f 128 160 162 +f 129 111 163 +f 128 179 158 +f 159 180 129 +f 156 158 179 +f 157 127 180 +f 154 156 126 +f 155 125 127 +f 152 154 124 +f 153 123 125 +f 150 152 122 +f 151 121 123 +f 148 150 120 +f 149 119 121 +f 146 148 118 +f 147 117 119 +f 164 146 116 +f 165 115 117 +f 114 181 177 +f 177 182 115 +f 162 68 112 +f 163 111 113 +f 112 68 178 +f 178 68 113 +f 181 183 178 +f 182 177 178 +f 135 137 176 +f 176 137 136 +f 133 135 174 +f 175 136 134 +f 133 172 170 +f 134 132 171 +f 166 187 185 +f 186 188 167 +f 131 170 168 +f 169 171 132 +f 190 189 187 +f 190 145 188 +f 187 189 69 +f 188 186 69 +f 131 185 69 +f 132 130 69 +f 142 193 191 +f 192 194 143 +f 140 195 193 +f 194 196 141 +f 197 195 140 +f 198 139 141 +f 71 197 139 +f 144 191 70 +f 145 190 70 +f 191 206 208 +f 192 70 208 +f 71 199 200 +f 201 199 71 +f 197 200 202 +f 203 201 198 +f 202 204 193 +f 203 196 194 +f 193 204 206 +f 207 205 194 +f 204 202 200 +f 205 199 201 +f 199 208 206 +f 207 208 199 +f 139 140 164 +f 165 141 139 +f 140 142 211 +f 212 143 141 +f 144 213 211 +f 145 143 212 +f 187 166 213 +f 188 145 214 +f 209 213 166 +f 210 82 167 +f 215 211 213 +f 216 210 214 +f 79 164 211 +f 212 165 80 +f 130 72 222 +f 130 132 223 +f 133 131 222 +f 223 132 134 +f 135 133 220 +f 221 134 136 +f 137 135 218 +f 219 136 137 +f 218 229 231 +f 219 217 231 +f 218 220 227 +f 228 221 219 +f 220 222 225 +f 226 223 221 +f 72 224 225 +f 72 223 226 +f 224 231 229 +f 230 231 224 +f 183 181 234 +f 235 182 184 +f 112 183 232 +f 233 184 113 +f 112 254 256 +f 113 111 257 +f 114 252 234 +f 115 182 235 +f 114 116 250 +f 251 117 115 +f 116 118 248 +f 249 119 117 +f 118 120 246 +f 247 121 119 +f 120 122 244 +f 245 123 121 +f 124 242 244 +f 125 123 245 +f 126 240 242 +f 127 125 243 +f 126 179 236 +f 237 180 127 +f 179 128 238 +f 239 129 180 +f 128 110 256 +f 257 111 129 +f 256 258 276 +f 257 239 277 +f 236 238 276 +f 277 239 237 +f 236 278 274 +f 237 241 275 +f 240 274 272 +f 241 243 273 +f 244 242 272 +f 273 243 245 +f 244 270 268 +f 245 247 269 +f 248 246 268 +f 269 247 249 +f 248 266 264 +f 249 251 265 +f 250 264 262 +f 251 253 263 +f 234 252 262 +f 263 253 235 +f 256 254 260 +f 261 255 257 +f 254 232 282 +f 283 233 255 +f 232 234 280 +f 281 235 233 +f 67 108 284 +f 285 109 67 +f 108 106 286 +f 287 107 109 +f 104 288 286 +f 105 107 287 +f 102 290 288 +f 103 105 289 +f 100 292 290 +f 101 103 291 +f 100 98 294 +f 295 99 101 +f 96 296 294 +f 97 99 295 +f 96 94 298 +f 299 95 97 +f 94 92 300 +f 301 93 95 +f 309 328 338 +f 309 308 339 +f 308 338 336 +f 308 307 337 +f 307 336 340 +f 307 306 341 +f 89 91 306 +f 306 91 90 +f 87 89 340 +f 341 90 88 +f 85 87 334 +f 335 88 86 +f 83 85 330 +f 331 86 84 +f 330 336 338 +f 339 337 331 +f 334 340 336 +f 335 331 337 +f 332 338 328 +f 333 327 329 +f 81 83 332 +f 333 84 82 +f 342 344 215 +f 343 210 216 +f 326 342 209 +f 327 82 210 +f 215 344 346 +f 216 80 347 +f 346 300 92 +f 347 80 93 +f 324 352 304 +f 325 77 304 +f 352 350 78 +f 353 304 78 +f 78 350 348 +f 349 351 78 +f 305 348 328 +f 329 349 305 +f 328 348 342 +f 329 327 343 +f 296 298 318 +f 319 299 297 +f 316 324 77 +f 317 76 77 +f 358 356 303 +f 359 302 303 +f 303 356 354 +f 355 357 303 +f 75 354 316 +f 317 355 75 +f 292 294 362 +f 363 295 293 +f 364 362 368 +f 369 363 365 +f 366 368 370 +f 371 369 367 +f 372 370 376 +f 377 371 373 +f 378 374 376 +f 379 315 377 +f 316 354 374 +f 375 355 317 +f 354 356 372 +f 373 357 355 +f 356 358 366 +f 367 359 357 +f 358 360 364 +f 365 361 359 +f 292 364 360 +f 293 291 361 +f 360 358 302 +f 361 74 302 +f 284 286 288 +f 289 287 285 +f 284 290 360 +f 361 291 285 +f 296 310 362 +f 297 295 363 +f 310 312 368 +f 369 313 311 +f 312 382 370 +f 371 383 313 +f 376 370 382 +f 377 315 383 +f 350 386 384 +f 351 349 385 +f 384 386 320 +f 385 319 321 +f 298 300 384 +f 385 301 299 +f 300 344 342 +f 343 345 301 +f 322 380 378 +f 323 315 379 +f 378 380 324 +f 379 317 325 +f 386 380 322 +f 387 321 323 +f 352 380 386 +f 353 351 387 +f 388 414 402 +f 389 401 403 +f 400 402 404 +f 405 403 401 +f 404 406 396 +f 405 399 397 +f 406 408 394 +f 407 397 395 +f 408 410 392 +f 409 395 393 +f 392 410 412 +f 413 411 393 +f 410 420 418 +f 419 421 411 +f 408 422 420 +f 421 423 409 +f 424 422 408 +f 425 407 409 +f 426 424 406 +f 427 405 407 +f 428 426 404 +f 429 403 405 +f 402 414 416 +f 417 415 403 +f 320 444 442 +f 321 319 443 +f 390 412 444 +f 391 321 445 +f 310 318 442 +f 443 319 311 +f 382 430 414 +f 415 431 383 +f 412 418 440 +f 441 419 413 +f 446 444 440 +f 447 439 441 +f 434 446 438 +f 439 447 435 +f 448 446 434 +f 449 433 435 +f 448 432 450 +f 449 431 451 +f 430 450 416 +f 431 415 417 +f 312 448 430 +f 431 449 313 +f 442 446 448 +f 443 313 449 +f 416 450 452 +f 453 451 417 +f 432 462 452 +f 433 451 453 +f 432 434 460 +f 461 435 433 +f 436 458 460 +f 437 435 461 +f 438 456 458 +f 439 437 459 +f 438 440 454 +f 455 441 439 +f 440 418 474 +f 475 419 441 +f 428 416 476 +f 477 417 429 +f 426 428 464 +f 465 429 427 +f 424 426 466 +f 467 427 425 +f 424 468 470 +f 425 423 471 +f 422 470 472 +f 423 421 473 +f 420 472 474 +f 421 419 475 +f 456 480 478 +f 457 459 479 +f 480 482 484 +f 481 479 485 +f 484 482 488 +f 489 483 485 +f 488 490 492 +f 489 487 493 +f 464 476 486 +f 487 477 465 +f 484 486 476 +f 485 453 477 +f 462 478 484 +f 463 453 485 +f 458 478 462 +f 463 479 459 +f 474 480 456 +f 475 455 457 +f 472 482 480 +f 481 483 473 +f 488 482 472 +f 489 471 473 +f 490 488 470 +f 491 469 471 +f 466 492 490 +f 491 493 467 +f 392 390 504 +f 505 391 393 +f 394 392 502 +f 503 393 395 +f 394 500 498 +f 395 397 499 +f 396 498 496 +f 397 399 497 +f 398 496 494 +f 399 401 495 +f 400 494 506 +f 401 389 507 +f 502 504 506 +f 503 495 507 +f 494 496 500 +f 501 497 495 +f 382 388 506 +f 383 315 507 +f 314 506 504 +f 505 507 315 +f 320 322 504 +f 505 323 321 diff --git a/include/geometry.hpp b/include/geometry.hpp new file mode 100644 index 0000000..59f08bc --- /dev/null +++ b/include/geometry.hpp @@ -0,0 +1,45 @@ +#ifndef GEOMETRY_HPP +#define GEOMETRY_HPP + +// Includes +#include +#include +#include +#include "graphics.hpp" + +// Object class +class Object { +public: + Object( + float *vertices, unsigned int vertex_size, + unsigned int *indices, unsigned int index_size, + float *normals = nullptr, unsigned int normal_size = 0, + float *texcoords = nullptr, unsigned int texcoord_size = 0 + ); + ~Object(); + void draw(); + +private: + unsigned int VAO, VBO, EBO, NBO, TBO; // Vertex Array Object, Vertex Buffer Object, Element Buffer Object, Normal Buffer Object, Texture Buffer Object + unsigned int vertex_count; + unsigned int index_count; +}; + +class UntexturedObject { +public: + UntexturedObject( + float *vertices, unsigned int vertex_size, + unsigned int *indices, unsigned int index_size, + float *normals = nullptr, unsigned int normal_size = 0, + float *texcoords = nullptr, unsigned int texcoord_size = 0 + ); + ~UntexturedObject(); + void draw(); + +private: + unsigned int VAO, VBO, EBO, NBO, TBO; // Vertex Array Object, Vertex Buffer Object, Element Buffer Object, Normal Buffer Object, Texture Buffer Object + unsigned int vertex_count; + unsigned int index_count; +}; + +#endif diff --git a/include/graphics.hpp b/include/graphics.hpp index 83a6a80..1d3d6ae 100644 --- a/include/graphics.hpp +++ b/include/graphics.hpp @@ -3,11 +3,11 @@ #define GL_GLEXT_PROTOTYPES // Includes -#include "imgui.h" -#include "imgui_impl_sdl3.h" -#include "imgui_impl_opengl3.h" #include #include "window.hpp" +#include "shader.hpp" +#include "texture.hpp" +#include // Constants const int open_gl_major_version = 3; @@ -21,25 +21,13 @@ extern float frame_time; extern float fps; extern float frame_time_graph[100]; extern SDL_GLContext gl_context; - -extern ImGuiIO& io; -extern ImGuiStyle& style; +#define delta_time frame_time // Functions int initialize_opengl(); void cleanup_opengl(); -// ImGui -int initialize_imgui(); -void cleanup_imgui(); -void new_frame_imgui(); -void frame_time_ui(); - // Frame time calculation void calc_frame_time(); -// Shader management -unsigned int compile_shader(const char* shader_source, GLenum shader_type); -unsigned int create_program(unsigned int vertex_shader, unsigned int fragment_shader); - #endif \ No newline at end of file diff --git a/include/gui.hpp b/include/gui.hpp new file mode 100644 index 0000000..29c42e7 --- /dev/null +++ b/include/gui.hpp @@ -0,0 +1,23 @@ +#ifndef GUI_HPP +#define GUI_HPP + +// Includes +#include "imgui.h" +#include "imgui_impl_sdl3.h" +#include "imgui_impl_opengl3.h" +#include "window.hpp" +#include "graphics.hpp" +#include + +// Variables +extern ImGuiIO& io; +extern ImGuiStyle& style; +extern + +// Functions +int initialize_imgui(); +void cleanup_imgui(); +void new_frame_imgui(); +void frame_time_ui(); + +#endif \ No newline at end of file diff --git a/include/loader.hpp b/include/loader.hpp new file mode 100644 index 0000000..42e6f9c --- /dev/null +++ b/include/loader.hpp @@ -0,0 +1,23 @@ +#ifndef LOADER_HPP +#define LOADER_HPP + +// Includes +#include +#include + +// Obj struct +struct Obj { + float* vertices; // Pointer to vertex data + size_t vertex_count; // Number of vertices + float* normals; // Pointer to normal data + size_t normal_count; // Number of normals + float* texcoords; // Pointer to texture coordinate data + size_t texcoord_count; // Number of texture coordinates + unsigned int* indices; // Pointer to index data + size_t index_count; // Number of indices +}; + +// Function to load an OBJ file +Obj load_obj(const std::string& filename); + +#endif // LOADER_HPP \ No newline at end of file diff --git a/include/main.hpp b/include/main.hpp index a3130dd..04b99fb 100644 --- a/include/main.hpp +++ b/include/main.hpp @@ -6,11 +6,17 @@ #include "window.hpp" #include "graphics.hpp" #include "utils.hpp" +#include "gui.hpp" +#include "geometry.hpp" +#include "loader.hpp" // Variables extern bool running; // Functions int main(int argc, char* argv[]); +void init(); // Initialize SDL, OpenGL, and ImGui +void handle_events(); // Handle SDL events +void handle_keyboard_input(); // Handle keyboard input for camera movement #endif \ No newline at end of file diff --git a/include/shader.hpp b/include/shader.hpp new file mode 100644 index 0000000..8b553ae --- /dev/null +++ b/include/shader.hpp @@ -0,0 +1,24 @@ +#ifndef SHADER_HPP +#define SHADER_HPP +#define GL_GLEXT_PROTOTYPES + +// Includes +#include "utils.hpp" +#include +#include +#include "geometry.hpp" + +// Shader class +class Shader { +public: + unsigned int ID; + Shader(const char* vertexPath, const char* fragmentPath); + void use() const; + void setBool(const std::string &name, bool value) const; + void setInt(const std::string &name, int value) const; + void setFloat(const std::string &name, float value) const; + void setMat4(const std::string &name, const glm::mat4 &mat) const; + ~Shader(); +}; + +#endif \ No newline at end of file diff --git a/include/texture.hpp b/include/texture.hpp new file mode 100644 index 0000000..fd0cbb3 --- /dev/null +++ b/include/texture.hpp @@ -0,0 +1,24 @@ +#ifndef TEXTURE_HPP +#define TEXTURE_HPP +#define GL_GLEXT_PROTOTYPES + +// Includes +#include +#include +#include + +// Functions +void flip_surface(SDL_Surface* surface); + +// Classes +class Texture { +public: + unsigned int ID; + Texture(const char* file_path); + ~Texture(); + void bind() const; + void bind(unsigned int unit) const; + void unbind() const; +}; + +#endif \ No newline at end of file diff --git a/include/window.hpp b/include/window.hpp index 31e8467..471e649 100644 --- a/include/window.hpp +++ b/include/window.hpp @@ -2,18 +2,16 @@ #define WINDOW_HPP // Includes -#include "iostream" +#include #include -// Constants -const int window_width = 800; -const int window_height = 600; - // Variables const SDL_WindowFlags window_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN | SDL_WINDOW_HIGH_PIXEL_DENSITY; extern float main_scale; extern SDL_Window* window; extern SDL_Event event; +extern int window_width; +extern int window_height; // Functions int initialize_sdl(); diff --git a/makefile b/makefile index b389898..98a85cf 100644 --- a/makefile +++ b/makefile @@ -10,10 +10,10 @@ IMGUI_DIR = imgui CXX = g++ # Libs -LIBS = -lGL `pkg-config --libs sdl3` +LIBS = -lGL -lglm `pkg-config --libs sdl3 sdl3-image` # Compiler and linker settings -CXXFLAGS = `pkg-config --cflags sdl3` -std=c++17 -I $(INCLUDE_DIR) +CXXFLAGS = -std=c++17 -I $(INCLUDE_DIR) # If ImGui directory is set, include its source files ifdef IMGUI_DIR @@ -51,6 +51,10 @@ dirs: @mkdir -p $(BUILD_DIR) @mkdir -p $(OBJ_DIR) +# Clear build directory +clear: + @find $(OBJ_DIR) -type f -name '*.o' ! -name 'imgui*.o' -exec rm -f {} + + # Pattern rule for source files in src directory $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(CXX) $(CXXFLAGS) -c -o $@ $< @@ -64,7 +68,7 @@ $(OBJ_DIR)/%.o: $(IMGUI_DIR)/backends/%.cpp $(CXX) $(CXXFLAGS) -c -o $@ $< endif -all: dirs $(BIN) +all: dirs clear $(BIN) @echo Build complete $(BIN): $(OBJS) diff --git a/shaders/triangle.frag b/shaders/triangle.frag index 5a2ecf0..e3a22a7 100644 --- a/shaders/triangle.frag +++ b/shaders/triangle.frag @@ -2,7 +2,11 @@ out vec4 FragColor; in vec3 color; // Input color from the vertex shader +in vec2 TexCoord; + +uniform sampler2D texture1; // Texture sampler +uniform sampler2D texture2; // Second texture sampler void main() { - FragColor = vec4(color, 1.0); // Set the fragment color to the input color + FragColor = mix(texture(texture1, TexCoord), texture(texture2, TexCoord), 0.3) * vec4(color, 1.0); // Mix the two textures and apply the color } \ No newline at end of file diff --git a/shaders/triangle.vert b/shaders/triangle.vert index 760e898..0145fc8 100644 --- a/shaders/triangle.vert +++ b/shaders/triangle.vert @@ -1,9 +1,16 @@ #version 330 core layout(location = 0) in vec3 position; // Vertex position +layout(location = 1) in vec2 texCoords; // Texture coordinates out vec3 color; // Output color to the fragment shader +out vec2 TexCoord; + +uniform mat4 model; +uniform mat4 view; +uniform mat4 projection; void main() { - gl_Position = vec4(position, 1.0); // Set the position of the vertex + gl_Position = projection * view * model * vec4(position, 1.0); // Apply transformation matrices color = position + vec3(0.5); // Set the color based on the vertex position + TexCoord = texCoords; // Pass texture coordinates to the fragment shader } \ No newline at end of file diff --git a/shaders/triangle_untextured.frag b/shaders/triangle_untextured.frag new file mode 100644 index 0000000..367732f --- /dev/null +++ b/shaders/triangle_untextured.frag @@ -0,0 +1,8 @@ +#version 330 core + +out vec4 FragColor; +in vec3 color; // Input color from the vertex shader + +void main() { + FragColor = vec4(color, 1.0); // Apply the color +} \ No newline at end of file diff --git a/shaders/triangle_untextured.vert b/shaders/triangle_untextured.vert new file mode 100644 index 0000000..920604a --- /dev/null +++ b/shaders/triangle_untextured.vert @@ -0,0 +1,13 @@ +#version 330 core + +layout(location = 0) in vec3 position; // Vertex position +out vec3 color; // Output color to the fragment shader + +uniform mat4 model; +uniform mat4 view; +uniform mat4 projection; + +void main() { + gl_Position = projection * view * model * vec4(position, 1.0); // Apply transformation matrices + color = position + vec3(0.5); // Set the color based on the vertex position +} \ No newline at end of file diff --git a/src/geometry.cpp b/src/geometry.cpp new file mode 100644 index 0000000..945b8ff --- /dev/null +++ b/src/geometry.cpp @@ -0,0 +1,120 @@ +#include "geometry.hpp" + +Object::Object( + float *vertices, unsigned int vertex_size, + unsigned int *indices, unsigned int index_size, + float *normals, unsigned int normal_size, + float *texcoords, unsigned int texcoord_size +) { + glGenVertexArrays(1, &VAO); // Generate a vertex array object + glGenBuffers(1, &VBO); // Generate a vertex buffer object + glGenBuffers(1, &EBO); // Generate an element buffer object + glGenBuffers(1, &NBO); // Generate a normal buffer object + glGenBuffers(1, &TBO); // Generate a texture buffer object + + glBindVertexArray(VAO); // Bind the vertex array object + glBindBuffer(GL_ARRAY_BUFFER, VBO); // Bind the vertex buffer object + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); // Bind the element buffer object + + glBufferData(GL_ARRAY_BUFFER, vertex_size, vertices, GL_STATIC_DRAW); // Upload vertex data to the buffer + glBufferData(GL_ELEMENT_ARRAY_BUFFER, index_size, indices, GL_STATIC_DRAW); // Upload index data to the buffer + + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0); // Set up vertex attributes + glEnableVertexAttribArray(0); // Enable vertex attribute 0 + + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float))); // Set up texture coordinates + glEnableVertexAttribArray(1); // Enable vertex attribute 1 + + if (normals && normal_size > 0) { + glBindBuffer(GL_ARRAY_BUFFER, NBO); // Bind the normal buffer object + glBufferData(GL_ARRAY_BUFFER, normal_size, normals, GL_STATIC_DRAW); // Upload normal data to the buffer + glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); // Set up normal attributes + glEnableVertexAttribArray(2); // Enable vertex attribute 2 + } + + if (texcoords && texcoord_size > 0) { + glBindBuffer(GL_ARRAY_BUFFER, TBO); // Bind the texture buffer object + glBufferData(GL_ARRAY_BUFFER, texcoord_size, texcoords, GL_STATIC_DRAW); // Upload texture coordinate data to the buffer + glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void*)0); // Set up texture coordinate attributes + glEnableVertexAttribArray(3); // Enable vertex attribute 3 + } + + glBindVertexArray(0); // Unbind the vertex array object + glBindBuffer(GL_ARRAY_BUFFER, 0); // Unbind the vertex buffer object + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); // Unbind the element buffer object + + this->vertex_count = vertex_size / (5 * sizeof(float)); // Calculate vertex count based on size + this->index_count = index_size / sizeof(unsigned int); // Calculate index count based on size +} + +Object::~Object() { + glDeleteVertexArrays(1, &VAO); // Delete the vertex array object + glDeleteBuffers(1, &VBO); // Delete the vertex buffer object + glDeleteBuffers(1, &EBO); // Delete the element buffer object + glDeleteBuffers(1, &NBO); // Delete the normal buffer object + glDeleteBuffers(1, &TBO); // Delete the texture buffer object +} + +void Object::draw() { + glBindVertexArray(VAO); // Bind the vertex array object + glDrawElements(GL_TRIANGLES, index_count, GL_UNSIGNED_INT, 0); // Draw the object using the element buffer + glBindVertexArray(0); // Unbind the vertex array object +} + +UntexturedObject::UntexturedObject( + float *vertices, unsigned int vertex_size, + unsigned int *indices, unsigned int index_size, + float *normals, unsigned int normal_size, + float *texcoords, unsigned int texcoord_size +) { + glGenVertexArrays(1, &VAO); // Generate a vertex array object + glGenBuffers(1, &VBO); // Generate a vertex buffer object + glGenBuffers(1, &EBO); // Generate an element buffer object + glGenBuffers(1, &NBO); // Generate a normal buffer object + glGenBuffers(1, &TBO); // Generate a texture buffer object + + glBindVertexArray(VAO); // Bind the vertex array object + glBindBuffer(GL_ARRAY_BUFFER, VBO); // Bind the vertex buffer object + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); // Bind the element buffer object + + glBufferData(GL_ARRAY_BUFFER, vertex_size, vertices, GL_STATIC_DRAW); // Upload vertex data to the buffer + glBufferData(GL_ELEMENT_ARRAY_BUFFER, index_size, indices, GL_STATIC_DRAW); // Upload index data to the buffer + + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); // Set up vertex attributes + glEnableVertexAttribArray(0); // Enable vertex attribute 0 + + if (normals && normal_size > 0) { + glBindBuffer(GL_ARRAY_BUFFER, NBO); // Bind the normal buffer object + glBufferData(GL_ARRAY_BUFFER, normal_size, normals, GL_STATIC_DRAW); // Upload normal data to the buffer + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); // Set up normal attributes + glEnableVertexAttribArray(1); // Enable vertex attribute 1 + } + + if (texcoords && texcoord_size > 0) { + glBindBuffer(GL_ARRAY_BUFFER, TBO); // Bind the texture buffer object + glBufferData(GL_ARRAY_BUFFER, texcoord_size, texcoords, GL_STATIC_DRAW); // Upload texture coordinate data to the buffer + glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void*)0); // Set up texture coordinate attributes + glEnableVertexAttribArray(2); // Enable vertex attribute 2 + } + + glBindVertexArray(0); // Unbind the vertex array object + glBindBuffer(GL_ARRAY_BUFFER, 0); // Unbind the vertex buffer object + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); // Unbind the element buffer object + + this->vertex_count = vertex_size / (5 * sizeof(float)); // Calculate vertex count based on size + this->index_count = index_size / sizeof(unsigned int); // Calculate index count based on +} + +UntexturedObject::~UntexturedObject() { + glDeleteVertexArrays(1, &VAO); // Delete the vertex array object + glDeleteBuffers(1, &VBO); // Delete the vertex buffer object + glDeleteBuffers(1, &EBO); // Delete the element buffer object + glDeleteBuffers(1, &NBO); // Delete the normal buffer object + glDeleteBuffers(1, &TBO); // Delete the texture buffer object +} + +void UntexturedObject::draw() { + glBindVertexArray(VAO); // Bind the vertex array object + glDrawElements(GL_TRIANGLES, index_count, GL_UNSIGNED_INT, 0); // Draw the object using the element buffer + glBindVertexArray(0); // Unbind the vertex array object +} \ No newline at end of file diff --git a/src/graphics.cpp b/src/graphics.cpp index 0532001..44f4e8a 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -6,7 +6,6 @@ Uint32 current_time; float frame_time; float fps; float frame_time_graph[100]; - SDL_GLContext gl_context; // Functions @@ -29,7 +28,7 @@ int initialize_opengl() { SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); SDL_ShowWindow(window); - glViewport(0, 0, (int)(window_width * main_scale), (int)(window_height * main_scale)); + glViewport(0, 0, (int)(window_width * main_scale), (int)(window_height * main_scale)); return 0; // OpenGL initialization successful } @@ -44,91 +43,6 @@ void cleanup_opengl() { std::cout << "OpenGL cleanup successful." << std::endl; } -unsigned int compile_shader(const char* shader_source, GLenum shader_type) { - unsigned int shader = glCreateShader(shader_type); - if (shader == 0) { - std::cerr << "Failed to create shader." << std::endl; - return 0; // Shader creation failed - } - - glShaderSource(shader, 1, &shader_source, nullptr); - glCompileShader(shader); - - // Check for compilation errors - int success; - glGetShaderiv(shader, GL_COMPILE_STATUS, &success); - if (!success) { - char info_log[512]; - glGetShaderInfoLog(shader, sizeof(info_log), nullptr, info_log); - std::cerr << "Shader compilation error: " << info_log << std::endl; - glDeleteShader(shader); - return 0; // Shader compilation failed - } - - return shader; // Shader compiled successfully -} - -unsigned int create_program(unsigned int vertex_shader, unsigned int fragment_shader) { - unsigned int program = glCreateProgram(); - if (program == 0) { - std::cerr << "Failed to create shader program." << std::endl; - return 0; // Program creation failed - } - - glAttachShader(program, vertex_shader); - glAttachShader(program, fragment_shader); - glLinkProgram(program); - - // Check for linking errors - int success; - glGetProgramiv(program, GL_LINK_STATUS, &success); - if (!success) { - char info_log[512]; - glGetProgramInfoLog(program, sizeof(info_log), nullptr, info_log); - std::cerr << "Shader program linking error: " << info_log << std::endl; - glDeleteProgram(program); - return 0; // Program linking failed - } - - return program; // Program created successfully -} - -int initialize_imgui() { - IMGUI_CHECKVERSION(); - ImGui::CreateContext(); - ImGuiIO& io = ImGui::GetIO(); (void)io; - io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; - io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; - - ImGui::StyleColorsDark(); - ImGuiStyle& style = ImGui::GetStyle(); - style.ScaleAllSizes(main_scale); - style.FontScaleDpi = main_scale; - - if (!ImGui_ImplSDL3_InitForOpenGL(window, gl_context)) { - std::cerr << "ImGui_ImplSDL3_InitForOpenGL failed!" << std::endl; - return 1; // Initialization failed - } - - char glsl_version[32]; - snprintf(glsl_version, sizeof(glsl_version), "#version %d%d0", open_gl_major_version, open_gl_minor_version); - if (!ImGui_ImplOpenGL3_Init(glsl_version)) { - std::cerr << "ImGui_ImplOpenGL3_Init failed!" << std::endl; - ImGui_ImplSDL3_Shutdown(); - ImGui::DestroyContext(); - return 1; // Initialization failed - } - - return 0; -} - -void cleanup_imgui() { - ImGui_ImplOpenGL3_Shutdown(); - ImGui_ImplSDL3_Shutdown(); - ImGui::DestroyContext(); - std::cout << "ImGui cleanup successful." << std::endl; -} - void calc_frame_time() { // Calculate frame time current_time = SDL_GetTicks(); @@ -141,18 +55,4 @@ void calc_frame_time() { frame_time_graph[i] = frame_time_graph[i - 1]; // Shift old values } frame_time_graph[0] = frame_time; // Add new frame time -} - -void new_frame_imgui() { - ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplSDL3_NewFrame(); - ImGui::NewFrame(); -} - -void frame_time_ui() { - ImGui::Begin("Frame Time"); - ImGui::Text("Current FPS: %.2f", fps); - ImGui::Text("Current Frame Time: %.3f ms", frame_time * 1000.0f); - ImGui::PlotLines("##Frame Time Graph", frame_time_graph, 100, 0, "Frame Time (ms)", 0.0f, 0.1f, ImVec2(200, 80)); - ImGui::End(); } \ No newline at end of file diff --git a/src/gui.cpp b/src/gui.cpp new file mode 100644 index 0000000..6a9cade --- /dev/null +++ b/src/gui.cpp @@ -0,0 +1,51 @@ +#include "gui.hpp" + +int initialize_imgui() { + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGuiIO& io = ImGui::GetIO(); (void)io; + //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; + io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; + + ImGui::StyleColorsDark(); + ImGuiStyle& style = ImGui::GetStyle(); + style.ScaleAllSizes(main_scale); + style.FontScaleDpi = main_scale; + + if (!ImGui_ImplSDL3_InitForOpenGL(window, gl_context)) { + std::cerr << "ImGui_ImplSDL3_InitForOpenGL failed!" << std::endl; + return 1; // Initialization failed + } + + char glsl_version[32]; + snprintf(glsl_version, sizeof(glsl_version), "#version %d%d0", open_gl_major_version, open_gl_minor_version); + if (!ImGui_ImplOpenGL3_Init(glsl_version)) { + std::cerr << "ImGui_ImplOpenGL3_Init failed!" << std::endl; + ImGui_ImplSDL3_Shutdown(); + ImGui::DestroyContext(); + return 1; // Initialization failed + } + + return 0; +} + +void cleanup_imgui() { + ImGui_ImplOpenGL3_Shutdown(); + ImGui_ImplSDL3_Shutdown(); + ImGui::DestroyContext(); + std::cout << "ImGui cleanup successful." << std::endl; +} + +void new_frame_imgui() { + ImGui_ImplOpenGL3_NewFrame(); + ImGui_ImplSDL3_NewFrame(); + ImGui::NewFrame(); +} + +void frame_time_ui() { + ImGui::Begin("Frame Time"); + ImGui::Text("Current FPS: %.2f", fps); + ImGui::Text("Current Frame Time: %.3f ms", frame_time * 1000.0f); + ImGui::PlotLines("##Frame Time Graph", frame_time_graph, 100, 0, "Frame Time (ms)", 0.0f, 0.1f, ImVec2(200, 80)); + ImGui::End(); +} \ No newline at end of file diff --git a/src/loader.cpp b/src/loader.cpp new file mode 100644 index 0000000..4845eee --- /dev/null +++ b/src/loader.cpp @@ -0,0 +1,48 @@ +#include "loader.hpp" + +Obj load_obj(const std::string& filename) { + Obj obj; + obj.vertices = nullptr; + obj.vertex_count = 0; + obj.indices = nullptr; + obj.index_count = 0; + obj.normals = nullptr; + obj.normal_count = 0; + obj.texcoords = nullptr; + obj.texcoord_count = 0; + + std::ifstream file(filename); + if (!file.is_open()) { + std::cerr << "Failed to open OBJ file: " << filename << std::endl; + return obj; + } + + // Read the file and populate the obj structure + std::string line; + while (std::getline(file, line)) { + // Parse the line and extract vertex, normal, and index data + if (line.substr(0, 2) == "v ") { + // Vertex position + obj.vertex_count++; + obj.vertices = (float*)realloc(obj.vertices, obj.vertex_count * 3 * sizeof(float)); + sscanf(line.c_str() + 2, "%f %f %f", &obj.vertices[(obj.vertex_count - 1) * 3], &obj.vertices[(obj.vertex_count - 1) * 3 + 1], &obj.vertices[(obj.vertex_count - 1) * 3 + 2]); + } else if (line.substr(0, 2) == "f ") { + // Face indices + unsigned int index1, + } else if (line.substr(0, 2) == "vn") { + // Vertex normal + obj.normal_count++; + obj.normals = (float*)realloc(obj.normals, obj.normal_count * 3 * sizeof(float)); + sscanf(line.c_str() + 3, "%f %f %f", &obj.normals[(obj.normal_count - 1) * 3], &obj.normals[(obj.normal_count - 1) * 3 + 1], &obj.normals[(obj.normal_count - 1) * 3 + 2]); + + } else if (line.substr(0, 2) == "vt") { + // Vertex texture coordinate + obj.texcoord_count++; + obj.texcoords = (float*)realloc(obj.texcoords, obj.texcoord_count * 2 * sizeof(float)); + sscanf(line.c_str() + 3, "%f %f", &obj.texcoords[(obj.texcoord_count - 1) * 2], &obj.texcoords[(obj.texcoord_count - 1) * 2 + 1]); + } + } + + file.close(); + return obj; +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index ef8a41d..e9029bf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,22 +1,33 @@ #include "main.hpp" -#include // Variables bool running = true; +float fov = 45.0f; // Field of view +float camera_move_speed = 10.0f; // Camera movement speed +bool wireframe_mode = false; // Wireframe mode toggle +glm::mat4 viewMatrix = glm::mat4(1.0f); // View matrix +glm::mat4 projectionMatrix = glm::perspective(glm::radians(fov), (float)window_width / (float)window_height, 0.1f, 100.0f); // Perspective projection matrix -// Main -int main(int argc, char* argv[]) { +glm::vec3 camera_position = glm::vec3(0.0f, 0.0f, 3.0f); // Initial camera position +glm::vec3 camera_front = glm::vec3(0.0f, 0.0f, -1.0f); // Camera front vector +glm::vec3 camera_up = glm::vec3(0.0f, 1.0f, 0.0f); // Camera up vector +float camera_pitch = 0.0f; // Pitch angle +float camera_yaw = -90.0f; // Yaw angle +float camera_turn_speed = 1.0f; // Camera turn speed + +// Init +void init() { // Initialize SDL if (initialize_sdl() != 0) { std::cerr << "SDL initialization failed." << std::endl; - return 1; // SDL initialization failed + return; } // Initialize OpenGL if (initialize_opengl() != 0) { std::cerr << "OpenGL initialization failed." << std::endl; cleanup_sdl(); - return 1; // OpenGL initialization failed + return; } // Initialize ImGui @@ -24,92 +35,159 @@ int main(int argc, char* argv[]) { std::cerr << "ImGui initialization failed." << std::endl; cleanup_opengl(); cleanup_sdl(); - return 1; // ImGui initialization failed + return; } - // Triangle vertices - float vertices[] = { - 0.5f, 0.5f, 0.0f, // top right - 0.5f, -0.5f, 0.0f, // bottom right - -0.5f, -0.5f, 0.0f, // bottom left - -0.5f, 0.5f, 0.0f // top left - }; + glEnable(GL_DEPTH_TEST); +} - unsigned int indices[] = { - 0, 1, 3, // first triangle - 1, 2, 3 // second triangle - }; +// Event handling +void handle_events() { + while (SDL_PollEvent(&event)) { + ImGui_ImplSDL3_ProcessEvent(&event); // Process ImGui events + switch (event.type) { + case SDL_EVENT_QUIT: + running = false; // Exit loop on quit event + break; + case SDL_EVENT_WINDOW_RESIZED: + // Handle window resize + SDL_GetWindowSize(window, &window_width, &window_height); + glViewport(0, 0, window_width, window_height); // Update OpenGL + break; - // Vertex buffer object (VBO) and vertex array object (VAO) and element buffer object (EBO) - unsigned int VBO, VAO, EBO; + default: + break; + } + } +} - glGenVertexArrays(1, &VAO); // Generate a vertex array object - glGenBuffers(1, &VBO); // Generate a vertex buffer object - glGenBuffers(1, &EBO); // Generate an element buffer object +// Handle keyboard input +void handle_keyboard_input() { + const bool *keyboard_state = SDL_GetKeyboardState(NULL); - glBindVertexArray(VAO); // Bind the vertex array object - glBindBuffer(GL_ARRAY_BUFFER, VBO); // Bind the vertex buffer object - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); // Bind the element buffer object + // Handle keyboard input for camera movement + if (keyboard_state[SDL_SCANCODE_W]) { + camera_position += camera_move_speed * delta_time * camera_front; // Move forward + } + if (keyboard_state[SDL_SCANCODE_S]) { + camera_position -= camera_move_speed * delta_time * camera_front; // Move backward + } + if (keyboard_state[SDL_SCANCODE_A]) { + camera_position -= glm::normalize(glm::cross(camera_front, camera_up)) * camera_move_speed * delta_time; // Move left + } + if (keyboard_state[SDL_SCANCODE_D]) { + camera_position += glm::normalize(glm::cross(camera_front, camera_up)) * camera_move_speed * delta_time; // Move right + } + if (keyboard_state[SDL_SCANCODE_SPACE]) { + camera_position += camera_up * camera_move_speed * delta_time; // Move up + } + if (keyboard_state[SDL_SCANCODE_LCTRL]) { + camera_position -= camera_up * camera_move_speed * delta_time; // Move down + } + if (keyboard_state[SDL_SCANCODE_LEFT]) { + camera_yaw -= camera_turn_speed; // Turn left + if (camera_yaw < -180.0f) camera_yaw += 360.0f; // Wrap yaw + } + if (keyboard_state[SDL_SCANCODE_RIGHT]) { + camera_yaw += camera_turn_speed; // Turn right + if (camera_yaw > 180.0f) camera_yaw -= 360.0f; // Wrap yaw + } + if (keyboard_state[SDL_SCANCODE_UP]) { + camera_pitch += camera_turn_speed; // Look up + if (camera_pitch > 89.0f) camera_pitch = 89.0f; // Clamp pitch + } + if (keyboard_state[SDL_SCANCODE_DOWN]) { + camera_pitch -= camera_turn_speed; // Look down + if (camera_pitch < -89.0f) camera_pitch = -89.0f; // Clamp pitch + } +} - // Upload vertex data to the buffer - glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); +// ImGui frame +void imgui_frame() { + new_frame_imgui(); - // Set up vertex attributes - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); - glEnableVertexAttribArray(0); + frame_time_ui(); - glBindVertexArray(0); // Unbind the vertex array object + ImGui::Begin("Control Panel"); + ImGui::Text("Camera Position: (%.2f, %.2f, %.2f)", camera_position.x, camera_position.y, camera_position.z); + ImGui::Text("Camera Front: (%.2f, %.2f, %.2f)", camera_front.x, camera_front.y, camera_front.z); + ImGui::Text("Camera Up: (%.2f, %.2f, %.2f)", camera_up.x, camera_up.y, camera_up.z); + ImGui::Text("Camera Pitch: %.2f degrees", camera_pitch); + ImGui::Text("Camera Yaw: %.2f degrees", camera_yaw); + ImGui::SliderFloat("Field of View", &fov, 1.0f, 120.0f, "%.1f degrees"); + ImGui::SliderFloat("Camera Speed", &camera_move_speed, 0.1f, 10.0f, "%.1f units/s"); + ImGui::SliderFloat("Camera Turn Speed", &camera_turn_speed, 1.0f, 5.0f, "%.2f units/s"); + ImGui::Checkbox("Wireframe Mode", &wireframe_mode); + if (wireframe_mode) { + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // Enable wireframe mode + } else { + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // Disable wireframe mode + } + ImGui::End(); +} - // Load shaders - const char* vertex_shader_source = read_file("shaders/triangle.vert"); - const char* fragment_shader_source = read_file("shaders/triangle.frag"); +// Main +int main(int argc, char* argv[]) { + // Initialize SDL, OpenGL, and ImGui + init(); - unsigned int vertex_shader = compile_shader(vertex_shader_source, GL_VERTEX_SHADER); - unsigned int fragment_shader = compile_shader(fragment_shader_source, GL_FRAGMENT_SHADER); - unsigned int shader_program = create_program(vertex_shader, fragment_shader); + // Load shader program + Shader shader_program("shaders/triangle_untextured.vert", "shaders/triangle_untextured.frag"); - // Set the shader program - glUseProgram(shader_program); + // Generate and set up textures + Texture texture1("assets/crate.jpg"); + Texture texture2("assets/meow.png"); + shader_program.use(); + shader_program.setInt("texture1", 0); + shader_program.setInt("texture2", 1); - // Wireframe toggle - bool wireframe_mode = false; + // Load an OBJ file + Obj obj = load_obj("assets/cube.obj"); + + // print vertex and index counts + std::cout << "Loaded OBJ file: " << obj.vertex_count << " vertices, " << obj.index_count << " indices." << std::endl; + + // Create the object and set up its geometry + UntexturedObject object( + obj.vertices, obj.vertex_count * 3 * sizeof(float), + obj.indices, obj.index_count * sizeof(unsigned int) + ); + + glm::mat4 modelMatrix = glm::mat4(1.0f); // Main loop while (running) { - // Handle events - while (SDL_PollEvent(&event)) { - ImGui_ImplSDL3_ProcessEvent(&event); // Process ImGui events - if (event.type == SDL_EVENT_QUIT) { - running = false; // Exit loop on quit event - } - } + handle_events(); + handle_keyboard_input(); - // Start the ImGui frame - new_frame_imgui(); - - // Frame time UI - frame_time_ui(); - - // Toggle wireframe mode ui - ImGui::Begin("Wireframe Mode"); - if (ImGui::Checkbox("Enable Wireframe Mode", &wireframe_mode)) { - if (wireframe_mode) { - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // Enable wireframe mode - } else { - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // Disable wireframe mode - } - } - ImGui::End(); + // ImGui frame + imgui_frame(); + + // Update the projection and view matrices + projectionMatrix = glm::perspective(glm::radians(fov), (float)window_width / (float)window_height, 0.1f, 100.0f); + camera_front = glm::vec3( + cos(glm::radians(camera_yaw)) * cos(glm::radians(camera_pitch)), + sin(glm::radians(camera_pitch)), + sin(glm::radians(camera_yaw)) * cos(glm::radians(camera_pitch)) + ); + viewMatrix = glm::lookAt(camera_position, camera_position + camera_front, camera_up); // Render ImGui::Render(); glClearColor(0.2f, 0.3f, 0.3f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glBindVertexArray(VAO); // Bind the vertex array object - glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); // Draw the triangles + // Use the shader program + shader_program.use(); + shader_program.setMat4("view", viewMatrix); // Set the view matrix + shader_program.setMat4("projection", projectionMatrix); // Set the projection matrix + shader_program.setMat4("model", modelMatrix); // Set the model matrix + + texture1.bind(0); // Bind texture 1 to unit 0 + texture2.bind(1); // Bind texture 2 to unit 1 + + object.draw(); // Draw the object ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); SDL_GL_SwapWindow(window); @@ -119,14 +197,6 @@ int main(int argc, char* argv[]) { } // Cleanup - glDeleteVertexArrays(1, &VAO); - glDeleteBuffers(1, &VBO); - glDeleteBuffers(1, &EBO); - glDeleteProgram(shader_program); - glDeleteShader(vertex_shader); - glDeleteShader(fragment_shader); - free((void*)vertex_shader_source); - free((void*)fragment_shader_source); cleanup_imgui(); cleanup_opengl(); cleanup_sdl(); diff --git a/src/shader.cpp b/src/shader.cpp new file mode 100644 index 0000000..a4b25f5 --- /dev/null +++ b/src/shader.cpp @@ -0,0 +1,97 @@ +#include "shader.hpp" + +Shader::Shader(const char* vertexPath, const char* fragmentPath) { + // Load and compile vertex shader + unsigned int shader = glCreateShader(GL_VERTEX_SHADER); + if (shader == 0) { + std::cerr << "Failed to create shader." << std::endl; + } + + const char* vertex_shader_source = read_file(vertexPath); + glShaderSource(shader, 1, &vertex_shader_source, nullptr); + glCompileShader(shader); + + // Check for vertex shader compilation errors + int success; + glGetShaderiv(shader, GL_COMPILE_STATUS, &success); + if (!success) { + char info_log[512]; + glGetShaderInfoLog(shader, sizeof(info_log), nullptr, info_log); + std::cerr << "Vertex shader compilation error: " << info_log << std::endl; + glDeleteShader(shader); + } + + // Load and compile fragment shader + unsigned int fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); + if (fragment_shader == 0) { + std::cerr << "Failed to create shader." << std::endl; + } + + const char* fragment_shader_source = read_file(fragmentPath); + glShaderSource(fragment_shader, 1, &fragment_shader_source, nullptr); + glCompileShader(fragment_shader); + + // Check for fragment shader compilation errors + glGetShaderiv(fragment_shader, GL_COMPILE_STATUS, &success); + if (!success) { + char info_log[512]; + glGetShaderInfoLog(fragment_shader, sizeof(info_log), nullptr, info_log); + std::cerr << "Fragment shader compilation error: " << info_log << std::endl; + glDeleteShader(fragment_shader); + } + + // Create shader program + ID = glCreateProgram(); + if (ID == 0) { + std::cerr << "Failed to create shader program." << std::endl; + } + + glAttachShader(ID, shader); + glAttachShader(ID, fragment_shader); + glLinkProgram(ID); + + // Check for linking errors + glGetProgramiv(ID, GL_LINK_STATUS, &success); + if (!success) { + char info_log[512]; + glGetProgramInfoLog(ID, sizeof(info_log), nullptr, info_log); + std::cerr << "Shader program linking error: " << info_log << std::endl; + glDeleteProgram(ID); + ID = 0; // Reset ID to indicate failure + } + + // Clean up shaders as they are no longer needed + glDeleteShader(shader); + glDeleteShader(fragment_shader); +} + +void Shader::use() const { + if (ID != 0) { + glUseProgram(ID); + } else { + std::cerr << "Shader program not initialized." << std::endl; + } +} + +void Shader::setBool(const std::string &name, bool value) const { + glUniform1i(glGetUniformLocation(ID, name.c_str()), (int)value); +} + +void Shader::setInt(const std::string &name, int value) const { + glUniform1i(glGetUniformLocation(ID, name.c_str()), value); +} + +void Shader::setFloat(const std::string &name, float value) const { + glUniform1f(glGetUniformLocation(ID, name.c_str()), value); +} + +void Shader::setMat4(const std::string &name, const glm::mat4 &mat) const { + glUniformMatrix4fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, &mat[0][0]); +} + +Shader::~Shader() { + if (ID != 0) { + glDeleteProgram(ID); + ID = 0; // Reset ID to indicate the shader program has been deleted + } +} \ No newline at end of file diff --git a/src/texture.cpp b/src/texture.cpp new file mode 100644 index 0000000..097a2bf --- /dev/null +++ b/src/texture.cpp @@ -0,0 +1,68 @@ +#include "texture.hpp" + +void flip_surface(SDL_Surface* surface) { + if (!surface) { + std::cerr << "Surface is null, cannot flip" << std::endl; + return; + } + + int pitch = surface->pitch; + Uint8* pixels = static_cast(surface->pixels); + int height = surface->h; + + for (int y = 0; y < height / 2; ++y) { + Uint8* top_row = pixels + y * pitch; + Uint8* bottom_row = pixels + (height - y - 1) * pitch; + + for (int x = 0; x < pitch; ++x) { + std::swap(top_row[x], bottom_row[x]); + } + } +} + +Texture::Texture(const char* file_path) { + ID = 0; + SDL_Surface* surface = IMG_Load(file_path); + if (!surface) { + std::cerr << "Failed to load texture: " << SDL_GetError() << std::endl; + return; // Texture loading failed + } + + GLenum format = (surface->format == SDL_PIXELFORMAT_RGBA32) ? GL_RGBA : GL_RGB; + flip_surface(surface); // Flip the surface vertically + + glGenTextures(1, &ID); + glBindTexture(GL_TEXTURE_2D, ID); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glTexImage2D(GL_TEXTURE_2D, 0, format, surface->w, surface->h, 0, format, GL_UNSIGNED_BYTE, surface->pixels); + glGenerateMipmap(GL_TEXTURE_2D); + + SDL_DestroySurface(surface); // Free the surface after uploading texture data +} + +Texture::~Texture() { + if (ID != 0) { + glDeleteTextures(1, &ID); + } +} + +void Texture::bind() const { + glBindTexture(GL_TEXTURE_2D, ID); +} + +void Texture::bind(unsigned int unit) const { + if (unit >= GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS) { + std::cerr << "Texture unit out of range: " << unit << std::endl; + return; // Invalid texture unit + } + glActiveTexture(GL_TEXTURE0 + unit); + glBindTexture(GL_TEXTURE_2D, ID); +} + +void Texture::unbind() const { + glBindTexture(GL_TEXTURE_2D, 0); +} \ No newline at end of file diff --git a/src/window.cpp b/src/window.cpp index d7547f9..396bd8c 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -4,6 +4,8 @@ float main_scale; SDL_Window* window; SDL_Event event; +int window_width = 850; // Default window width +int window_height = 850; // Default window height // Functions int initialize_sdl() {