Main: add basic lightning

This commit is contained in:
0xdeadbeer 2023-10-15 20:38:47 +02:00
parent d5429ad5af
commit a48ab901cb
13 changed files with 42106 additions and 39 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
cmake-build-debug/
build/
.ccls-cache/
*.mtl

View File

@ -3,12 +3,16 @@ project(ssts C)
set(SOURCE_FILES main.c)
set(HEADER_FILES )
set(SHADER_FILES shader.vert shader.frag)
foreach(SHADER IN LISTS SHADER_FILES)
configure_file(${SHADER} ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
endforeach()
add_executable(${PROJECT_NAME} ${HEADER_FILES} ${SOURCE_FILES} ${SHADER_FILES})
add_executable(${PROJECT_NAME} ${HEADER_FILES} ${SOURCE_FILES})
# dependencies
add_custom_target(assets ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory
${PROJECT_SOURCE_DIR}/assets
${PROJECT_BINARY_DIR}/assets
COMMENT "Copying assets to build folder")
add_dependencies(ssts assets)
# We need a CMAKE_DIR with some code to find external dependencies
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
@ -21,5 +25,4 @@ find_package(assimp REQUIRED)
find_package(cglm REQUIRED)
include_directories(${PROJECT_NAME} ${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS} ${GLEW_INCLUDE_DIRS} ${ASSIMP_INCLUDE_DIRS} ${CGLM_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} ${GLEW_LIBRARIES} ${ASSIMP_LIBRARIES} ${CGLM_LIBRARIES} m)

40
assets/models/kub.obj Normal file
View File

@ -0,0 +1,40 @@
# Blender 3.6.4
# www.blender.org
mtllib kub.mtl
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
vn -0.0000 1.0000 -0.0000
vn -0.0000 -0.0000 1.0000
vn -1.0000 -0.0000 -0.0000
vn -0.0000 -1.0000 -0.0000
vn 1.0000 -0.0000 -0.0000
vn -0.0000 -0.0000 -1.0000
vt 0.625000 0.500000
vt 0.875000 0.500000
vt 0.875000 0.750000
vt 0.625000 0.750000
vt 0.375000 0.750000
vt 0.625000 1.000000
vt 0.375000 1.000000
vt 0.375000 0.000000
vt 0.625000 0.000000
vt 0.625000 0.250000
vt 0.375000 0.250000
vt 0.125000 0.500000
vt 0.375000 0.500000
vt 0.125000 0.750000
s 0
usemtl Material
f 1/1/1 5/2/1 7/3/1 3/4/1
f 4/5/2 3/4/2 7/6/2 8/7/2
f 8/8/3 7/9/3 5/10/3 6/11/3
f 6/12/4 2/13/4 4/5/4 8/14/4
f 2/13/5 1/1/5 3/4/5 4/5/5
f 6/11/6 5/10/6 1/1/6 2/13/6

2075
assets/models/monkey.obj Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

2070
assets/models/sphere.obj Normal file

File diff suppressed because it is too large Load Diff

11973
assets/models/statue.obj Normal file

File diff suppressed because it is too large Load Diff

722
assets/models/tower.obj Normal file
View File

@ -0,0 +1,722 @@
# Blender v3.6.4 OBJ File: 'tower.blend'
# www.blender.org
mtllib tower.mtl
o tower_mesh
v 1.153154 0.000000 -1.153154
v 1.153154 -0.000000 1.153154
v -1.153154 -0.000000 1.153154
v -1.153154 0.000000 -1.153154
v -1.028331 1.070182 1.028331
v 1.028331 1.070182 1.028331
v 1.028331 1.070182 -1.028331
v -1.028331 1.070182 -1.028331
v -0.941177 2.560001 0.941177
v 0.941177 2.560001 0.941177
v 1.280001 2.880001 1.280001
v -1.280001 2.880001 1.280001
v 0.941177 2.560001 -0.941176
v 1.280001 2.880002 -1.280000
v -0.941177 2.560001 -0.941176
v -1.280001 2.880002 -1.280000
v 1.280001 3.232043 1.280001
v -1.280001 3.232043 1.280001
v 1.280001 3.232043 -1.280000
v -1.280001 3.232043 -1.280000
v -1.256075 3.260410 1.256076
v 1.256075 3.260410 1.256076
v 1.256075 4.009310 1.256076
v -1.256075 4.009310 1.256076
v 1.256075 3.260411 -1.256075
v 1.256075 4.009310 -1.256075
v -1.256075 3.260411 -1.256075
v -1.256075 4.009310 -1.256075
v 1.333334 3.060002 -1.333333
v 1.333334 3.060002 -0.920000
v 0.920000 3.060002 -0.920000
v 0.920000 3.060002 -1.333333
v 1.340001 3.540002 -1.340000
v 0.920000 3.540002 -1.340000
v 0.920000 3.540002 -0.920000
v 1.340001 3.540002 -0.920000
v 1.391747 3.480572 -0.920000
v 1.391747 3.480572 -1.391746
v 0.920000 3.480572 -1.391746
v -0.920000 3.060001 0.920001
v -0.920000 3.060001 1.333334
v -1.333334 3.060001 1.333334
v -1.333334 3.060001 0.920001
v -0.920000 3.540001 0.920001
v -1.340001 3.540001 0.920001
v -1.340001 3.540001 1.340001
v -0.920000 3.540001 1.340001
v -0.920000 3.480572 1.391747
v -1.391747 3.480572 1.391747
v -1.391747 3.480572 0.920001
v 1.333334 3.060001 0.920001
v 1.333334 3.060001 1.333334
v 0.920000 3.060001 1.333334
v 0.920000 3.060001 0.920001
v 1.340001 3.540001 0.920001
v 0.920000 3.540001 0.920001
v 0.920000 3.540001 1.340001
v 1.340001 3.540001 1.340001
v 1.391747 3.480572 1.391747
v 0.920000 3.480572 1.391747
v 1.391747 3.480572 0.920001
v -0.920000 3.060002 -1.333333
v -0.920000 3.060002 -0.920000
v -1.333334 3.060002 -0.920000
v -1.333334 3.060002 -1.333333
v -0.920000 3.514277 -1.306006
v -1.336425 3.514277 -1.306006
v -1.339998 3.540002 -0.920000
v -0.920000 3.540002 -0.920000
v -1.391728 3.480438 -0.920000
v -0.920000 3.450443 -1.361548
v -1.387601 3.450727 -1.361569
v -0.920000 3.060001 0.146667
v -0.920000 3.060001 0.626667
v -1.333334 3.060001 0.626667
v -1.333334 3.060001 0.146667
v -0.920000 3.540002 0.146667
v -1.340001 3.540002 0.146667
v -1.340001 3.540002 0.626667
v -0.920000 3.540002 0.626667
v -1.391747 3.480572 0.626667
v -1.391747 3.480572 0.146667
v -0.920000 3.060001 -0.626667
v -0.920000 3.060001 -0.146666
v -1.333334 3.060001 -0.146666
v -1.333334 3.060001 -0.626667
v -0.920000 3.540002 -0.626666
v -1.340001 3.540002 -0.626666
v -1.340001 3.540002 -0.146666
v -0.920000 3.540002 -0.146666
v -1.391747 3.480572 -0.146666
v -1.391747 3.480572 -0.626666
v -0.146667 3.060002 -1.333333
v -0.146667 3.060002 -0.920000
v -0.626667 3.060002 -0.920000
v -0.626667 3.060002 -1.333333
v -0.146667 3.540002 -1.340000
v -0.626667 3.540002 -1.340000
v -0.626667 3.540002 -0.920000
v -0.146667 3.540002 -0.920000
v -0.146667 3.480572 -1.391746
v -0.626667 3.480572 -1.391746
v 0.626667 3.060002 -1.333333
v 0.626667 3.060002 -0.920000
v 0.146667 3.060002 -0.920000
v 0.146667 3.060002 -1.333333
v 0.626667 3.540002 -1.340000
v 0.146667 3.540002 -1.340000
v 0.146667 3.540002 -0.920000
v 0.626667 3.540002 -0.920000
v 0.626667 3.480572 -1.391746
v 0.146667 3.480572 -1.391746
v -0.146667 3.060001 0.920001
v -0.146667 3.060001 1.333334
v -0.626667 3.060001 1.333334
v -0.626667 3.060001 0.920001
v -0.146667 3.540001 0.920001
v -0.626667 3.540001 0.920001
v -0.626667 3.540001 1.340001
v -0.146667 3.540001 1.340001
v -0.146667 3.480572 1.391747
v -0.626667 3.480572 1.391747
v 0.626667 3.060001 0.920001
v 0.626667 3.060001 1.333334
v 0.146667 3.060001 1.333334
v 0.146667 3.060001 0.920001
v 0.626667 3.540001 0.920001
v 0.146667 3.540001 0.920001
v 0.146667 3.540001 1.340001
v 0.626667 3.540001 1.340001
v 0.626667 3.480572 1.391747
v 0.146667 3.480572 1.391747
v 1.333334 3.060001 0.146667
v 1.333334 3.060001 0.626667
v 0.920000 3.060001 0.626667
v 0.920000 3.060001 0.146667
v 1.340001 3.540002 0.146667
v 0.920000 3.540002 0.146667
v 0.920000 3.540002 0.626667
v 1.340001 3.540002 0.626667
v 1.391747 3.480572 0.626667
v 1.391747 3.480572 0.146667
v 1.333334 3.060001 -0.626667
v 1.333334 3.060001 -0.146666
v 0.920000 3.060001 -0.146666
v 0.920000 3.060001 -0.626667
v 1.340001 3.540002 -0.626666
v 0.920000 3.540002 -0.626666
v 0.920000 3.540002 -0.146666
v 1.340001 3.540002 -0.146666
v 1.391747 3.480572 -0.146666
v 1.391747 3.480572 -0.626666
v 1.395895 3.879018 -1.395894
v -1.395894 3.879018 -1.395894
v 0.000000 5.247541 0.000001
v -1.395894 3.879018 1.395895
v 1.395895 3.879018 1.395895
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.500917 0.234569
vt 0.474622 0.014198
vt 0.960465 0.014198
vt 0.934170 0.234569
vt 0.960465 0.014198
vt 0.934170 0.234569
vt 0.500917 0.234569
vt 0.474622 0.014198
vt 0.500917 0.234480
vt 0.474622 0.014168
vt 0.960465 0.014169
vt 0.934170 0.234480
vt 0.500917 0.234569
vt 0.474622 0.014198
vt 0.960465 0.014198
vt 0.934170 0.234569
vt 0.519277 0.540839
vt 0.915811 0.540839
vt 0.987187 0.604708
vt 0.447901 0.604708
vt 0.519277 0.540839
vt 0.915811 0.540839
vt 0.987187 0.604708
vt 0.447901 0.604708
vt 0.519277 0.540839
vt 0.915811 0.540839
vt 0.987187 0.604626
vt 0.447901 0.604626
vt 0.519277 0.540839
vt 0.915811 0.540839
vt 0.987187 0.604708
vt 0.447901 0.604708
vt 0.987187 0.676956
vt 0.447901 0.676956
vt 0.987187 0.676956
vt 0.447901 0.676956
vt 0.987187 0.676938
vt 0.447901 0.676938
vt 0.987187 0.676956
vt 0.447901 0.676956
vt 0.454948 0.697654
vt 0.983421 0.697654
vt 0.983421 0.846940
vt 0.454948 0.846940
vt 0.454948 0.697654
vt 0.983421 0.697654
vt 0.983421 0.846940
vt 0.454948 0.846940
vt 0.454948 0.697654
vt 0.983421 0.697654
vt 0.983421 0.846940
vt 0.454948 0.846940
vt 0.454948 0.697654
vt 0.983421 0.697654
vt 0.983421 0.846940
vt 0.454948 0.846940
vt 0.982147 0.689163
vt 0.452941 0.689163
vt 0.982147 0.689163
vt 0.452941 0.689163
vt 0.982147 0.689112
vt 0.452941 0.689112
vt 0.982147 0.689163
vt 0.452941 0.689163
vt 0.115366 0.859635
vt 0.241273 0.859814
vt 0.241273 0.985830
vt 0.115252 0.985837
vt 0.306511 0.328040
vt 0.433652 0.328040
vt 0.433653 0.203167
vt 0.306242 0.203156
vt 0.634430 0.998147
vt 0.517933 0.850990
vt 0.632565 0.850995
vt 0.648803 0.975125
vt 0.794501 0.975387
vt 0.924950 0.975417
vt 0.925125 0.851559
vt 0.810142 0.851559
vt 0.924961 0.975414
vt 0.794653 0.975339
vt 0.810159 0.851554
vt 0.925148 0.851552
vt 0.517932 0.998122
vt 0.648804 0.975057
vt 0.632566 0.850914
vt 0.517933 0.850920
vt 0.241223 0.985912
vt 0.115211 0.985905
vt 0.115098 0.860074
vt 0.241223 0.859895
vt 0.433650 0.203224
vt 0.306238 0.203236
vt 0.306511 0.328043
vt 0.433652 0.328042
vt 0.924960 0.975417
vt 0.794653 0.975387
vt 0.810159 0.851559
vt 0.925147 0.851559
vt 0.517930 0.998122
vt 0.648796 0.975057
vt 0.632556 0.850914
vt 0.517929 0.850920
vt 0.634381 0.998147
vt 0.517930 0.850990
vt 0.632557 0.850995
vt 0.648797 0.975125
vt 0.794499 0.975397
vt 0.924953 0.975417
vt 0.925133 0.851566
vt 0.810143 0.851565
vt 0.241223 0.859814
vt 0.115098 0.859635
vt 0.115211 0.985837
vt 0.241223 0.985830
vt 0.306242 0.203236
vt 0.433653 0.203224
vt 0.433652 0.328042
vt 0.306511 0.328043
vt 0.794501 0.975387
vt 0.924950 0.975417
vt 0.925125 0.851559
vt 0.810142 0.851559
vt 0.924960 0.975417
vt 0.794653 0.975387
vt 0.810159 0.851559
vt 0.925147 0.851559
vt 0.517932 0.998173
vt 0.648803 0.975125
vt 0.632565 0.850995
vt 0.517933 0.850990
vt 0.634377 0.998143
vt 0.517929 0.850920
vt 0.632556 0.850914
vt 0.648796 0.975057
vt 0.115252 0.985905
vt 0.241273 0.985912
vt 0.241273 0.859895
vt 0.115366 0.860074
vt 0.433652 0.328037
vt 0.306511 0.328035
vt 0.306238 0.203156
vt 0.433650 0.203167
vt 0.517930 0.998173
vt 0.648797 0.975118
vt 0.632557 0.850995
vt 0.517930 0.850990
vt 0.634433 0.998142
vt 0.517933 0.850920
vt 0.632566 0.850914
vt 0.648805 0.974807
vt 0.794451 0.975376
vt 0.924944 0.975416
vt 0.925120 0.851552
vt 0.810137 0.851554
vt 0.924943 0.975414
vt 0.794554 0.975315
vt 0.925111 0.851560
vt 0.409205 0.985236
vt 0.262866 0.985236
vt 0.262924 0.859229
vt 0.409208 0.859220
vt 0.435227 0.036608
vt 0.307816 0.036608
vt 0.307819 0.182201
vt 0.435230 0.182203
vt 0.517930 0.998173
vt 0.648797 0.975125
vt 0.632557 0.850995
vt 0.517930 0.850990
vt 0.634381 0.998147
vt 0.517930 0.850990
vt 0.632557 0.850995
vt 0.648797 0.975125
vt 0.654777 0.975142
vt 0.788304 0.975138
vt 0.788302 0.851395
vt 0.654785 0.851425
vt 0.262878 0.985236
vt 0.409216 0.985236
vt 0.409219 0.859220
vt 0.262926 0.859229
vt 0.435230 0.182168
vt 0.307819 0.182169
vt 0.307816 0.036538
vt 0.435227 0.036538
vt 0.517930 0.998173
vt 0.648797 0.975125
vt 0.632557 0.850995
vt 0.517930 0.850990
vt 0.634381 0.998147
vt 0.517930 0.850990
vt 0.632557 0.850995
vt 0.648797 0.975125
vt 0.788296 0.975137
vt 0.654721 0.975130
vt 0.654689 0.851406
vt 0.788299 0.851395
vt 0.262948 0.859235
vt 0.262993 0.985273
vt 0.409338 0.985274
vt 0.409335 0.859256
vt 0.307840 0.182182
vt 0.307861 0.036567
vt 0.435273 0.036567
vt 0.435253 0.182182
vt 0.634434 0.998143
vt 0.517933 0.850920
vt 0.632566 0.850914
vt 0.648804 0.975057
vt 0.654734 0.975126
vt 0.788295 0.975136
vt 0.788299 0.851393
vt 0.654713 0.851369
vt 0.517932 0.998122
vt 0.648804 0.975057
vt 0.632566 0.850914
vt 0.517933 0.850920
vt 0.409353 0.859256
vt 0.409357 0.985274
vt 0.263012 0.985273
vt 0.262951 0.859235
vt 0.307861 0.036571
vt 0.307840 0.182184
vt 0.435253 0.182184
vt 0.435273 0.036571
vt 0.634434 0.998143
vt 0.517933 0.850920
vt 0.632566 0.850914
vt 0.648804 0.975057
vt 0.788306 0.975136
vt 0.654809 0.975126
vt 0.654835 0.851369
vt 0.788302 0.851393
vt 0.517932 0.998122
vt 0.648804 0.975057
vt 0.632566 0.850914
vt 0.517933 0.850920
vt 0.262993 0.985261
vt 0.262948 0.859233
vt 0.409335 0.859245
vt 0.409338 0.985262
vt 0.435218 0.182182
vt 0.435203 0.036567
vt 0.307791 0.036567
vt 0.307808 0.182182
vt 0.788305 0.975139
vt 0.654805 0.975145
vt 0.654828 0.851396
vt 0.788302 0.851394
vt 0.517930 0.998122
vt 0.648796 0.975057
vt 0.632556 0.850914
vt 0.517929 0.850920
vt 0.634377 0.998143
vt 0.517929 0.850920
vt 0.632556 0.850914
vt 0.648796 0.975057
vt 0.409357 0.985262
vt 0.409353 0.859245
vt 0.262951 0.859233
vt 0.263012 0.985261
vt 0.435203 0.036571
vt 0.435218 0.182184
vt 0.307808 0.182184
vt 0.307791 0.036571
vt 0.654746 0.975145
vt 0.788296 0.975139
vt 0.788299 0.851394
vt 0.654732 0.851396
vt 0.517930 0.998122
vt 0.648796 0.975057
vt 0.632556 0.850914
vt 0.517929 0.850920
vt 0.634377 0.998143
vt 0.517929 0.850920
vt 0.632556 0.850914
vt 0.648796 0.975057
vt 0.409208 0.859202
vt 0.262924 0.859226
vt 0.262866 0.985218
vt 0.409205 0.985217
vt 0.307820 0.036608
vt 0.435231 0.036608
vt 0.435232 0.182203
vt 0.307821 0.182201
vt 0.634430 0.998147
vt 0.517933 0.850990
vt 0.632565 0.850995
vt 0.648803 0.975125
vt 0.788305 0.975139
vt 0.654805 0.975145
vt 0.654828 0.851396
vt 0.788302 0.851394
vt 0.517932 0.998173
vt 0.648803 0.975125
vt 0.632565 0.850995
vt 0.517933 0.850990
vt 0.262926 0.859226
vt 0.409219 0.859202
vt 0.409216 0.985217
vt 0.262878 0.985218
vt 0.307821 0.182169
vt 0.435232 0.182168
vt 0.435231 0.036538
vt 0.307820 0.036538
vt 0.634430 0.998147
vt 0.517933 0.850990
vt 0.632565 0.850995
vt 0.648803 0.975125
vt 0.654746 0.975145
vt 0.788296 0.975139
vt 0.788299 0.851394
vt 0.654732 0.851396
vt 0.517932 0.998173
vt 0.648803 0.975125
vt 0.632565 0.850995
vt 0.517933 0.850990
vt 0.809024 0.998735
vt 0.924949 0.998642
vt 0.924963 0.998638
vt 0.809131 0.998704
vt 0.924962 0.998642
vt 0.809130 0.998735
vt 0.809029 0.998734
vt 0.924954 0.998641
vt 0.809024 0.998735
vt 0.924949 0.998642
vt 0.924962 0.998642
vt 0.809130 0.998735
vt 0.654771 0.998144
vt 0.788304 0.998143
vt 0.788295 0.998142
vt 0.654754 0.998140
vt 0.654758 0.998141
vt 0.788295 0.998142
vt 0.788307 0.998142
vt 0.654780 0.998141
vt 0.788305 0.998145
vt 0.654779 0.998146
vt 0.654761 0.998146
vt 0.788296 0.998145
vt 0.788305 0.998145
vt 0.654779 0.998146
vt 0.654761 0.998146
vt 0.788296 0.998145
vt 0.924941 0.998637
vt 0.809088 0.998708
vt 0.808985 0.998771
vt 0.924942 0.998646
vt 0.016326 0.907086
vt 0.016326 0.141896
vt 0.497578 0.524491
vt 0.016326 0.907086
vt 0.016326 0.141896
vt 0.016326 0.907086
vt 0.016326 0.141896
vt 0.016326 0.907086
vt 0.016326 0.141896
vt 0.517932 0.998173
vt 0.634434 0.998143
vt 0.634377 0.998143
vt 0.517930 0.998173
vt 0.634430 0.998147
vt 0.517930 0.998122
vt 0.634381 0.998147
vt 0.517932 0.998122
vt 0.634381 0.998147
vt 0.517930 0.998173
vt 0.634381 0.998147
vt 0.517930 0.998173
vt 0.517932 0.998122
vt 0.634434 0.998143
vt 0.517932 0.998122
vt 0.634434 0.998143
vt 0.634377 0.998143
vt 0.517930 0.998122
vt 0.634377 0.998143
vt 0.517930 0.998122
vt 0.517932 0.998173
vt 0.634430 0.998147
vt 0.517932 0.998173
vt 0.634430 0.998147
vn 0.0000 -1.0000 -0.0000
vn 0.0000 0.1159 0.9933
vn 0.9933 0.1159 0.0000
vn 0.0000 0.1159 -0.9933
vn -0.9933 0.1159 0.0000
vn 0.0000 -0.7270 0.6866
vn 0.6866 -0.7270 -0.0000
vn 0.0000 -0.7270 -0.6866
vn -0.6866 -0.7270 -0.0000
vn 0.0000 0.0000 1.0000
vn 1.0000 0.0000 0.0000
vn 0.0000 0.0000 -1.0000
vn -1.0000 0.0000 0.0000
vn 0.0000 0.6447 0.7644
vn 0.7644 0.6447 0.0000
vn 0.0000 0.6447 -0.7644
vn -0.7644 0.6447 0.0000
vn -0.0000 0.0584 0.9983
vn 0.9983 0.0584 0.0000
vn 0.0000 0.0584 -0.9983
vn -0.9983 0.0584 0.0000
vn 0.0000 1.0000 0.0000
vn 0.9905 -0.1376 -0.0000
vn 0.0000 -0.1376 -0.9905
vn 0.0000 -0.1376 0.9905
vn -0.9905 -0.1376 0.0000
vn 0.0000 0.9978 -0.0665
vn 0.0000 -0.0721 -0.9974
vn 0.7542 0.6567 0.0000
vn 0.0000 0.6567 -0.7542
vn 0.0000 0.6567 0.7542
vn -0.7542 0.6567 0.0000
vn -0.7549 0.6539 -0.0508
vn 0.0002 0.6573 -0.7537
vn 0.0000 0.7141 -0.7001
vn -0.7001 0.7141 0.0000
vn 0.0000 0.7141 0.7001
vn 0.7001 0.7141 0.0000
usemtl Material
s off
f 1/1/1 2/2/1 3/3/1 4/4/1
f 5/5/2 3/6/2 2/7/2 6/8/2
f 1/9/3 7/10/3 6/11/3 2/12/3
f 7/13/4 1/14/4 4/15/4 8/16/4
f 8/17/5 4/18/5 3/19/5 5/20/5
f 9/21/6 10/22/6 11/23/6 12/24/6
f 10/25/7 13/26/7 14/27/7 11/28/7
f 13/29/8 15/30/8 16/31/8 14/32/8
f 15/33/9 9/34/9 12/35/9 16/36/9
f 12/24/10 11/23/10 17/37/10 18/38/10
f 11/28/11 14/27/11 19/39/11 17/40/11
f 14/32/12 16/31/12 20/41/12 19/42/12
f 16/36/13 12/35/13 18/43/13 20/44/13
f 21/45/10 22/46/10 23/47/10 24/48/10
f 22/49/11 25/50/11 26/51/11 23/52/11
f 25/53/12 27/54/12 28/55/12 26/56/12
f 27/57/13 21/58/13 24/59/13 28/60/13
f 22/61/14 21/62/14 18/38/14 17/37/14
f 25/63/15 22/64/15 17/40/15 19/39/15
f 27/65/16 25/66/16 19/42/16 20/41/16
f 21/67/17 27/68/17 20/44/17 18/43/17
f 5/5/18 6/8/18 10/22/18 9/21/18
f 6/11/19 7/10/19 13/26/19 10/25/19
f 7/13/20 8/16/20 15/30/20 13/29/20
f 8/17/21 5/20/21 9/34/21 15/33/21
f 29/69/1 30/70/1 31/71/1 32/72/1
f 33/73/22 34/74/22 35/75/22 36/76/22
f 36/77/10 31/78/10 30/79/10 37/80/10
f 38/81/23 37/82/23 30/83/23 29/84/23
f 39/85/24 38/86/24 29/87/24 32/88/24
f 35/89/13 39/90/13 32/91/13 31/92/13
f 40/93/1 41/94/1 42/95/1 43/96/1
f 44/97/22 45/98/22 46/99/22 47/100/22
f 48/101/25 49/102/25 42/103/25 41/104/25
f 44/105/11 48/106/11 41/107/11 40/108/11
f 45/109/12 40/110/12 43/111/12 50/112/12
f 49/113/26 50/114/26 43/115/26 42/116/26
f 51/117/1 52/118/1 53/119/1 54/120/1
f 55/121/22 56/122/22 57/123/22 58/124/22
f 59/125/25 60/126/25 53/127/25 52/128/25
f 61/129/23 59/130/23 52/131/23 51/132/23
f 56/133/12 61/134/12 51/135/12 54/136/12
f 57/137/13 54/138/13 53/139/13 60/140/13
f 62/141/1 63/142/1 64/143/1 65/144/1
f 66/145/27 67/146/27 68/147/27 69/148/27
f 69/149/10 70/150/10 64/151/10 63/152/10
f 66/153/11 63/154/11 62/155/11 71/156/11
f 72/157/28 71/158/28 62/159/28 65/160/28
f 70/161/26 72/162/26 65/160/26 64/163/26
f 73/164/1 74/165/1 75/166/1 76/167/1
f 77/168/22 78/169/22 79/170/22 80/171/22
f 80/172/10 81/173/10 75/174/10 74/175/10
f 78/176/12 73/177/12 76/178/12 82/179/12
f 81/180/26 82/181/26 76/182/26 75/183/26
f 83/184/1 84/185/1 85/186/1 86/187/1
f 87/188/22 88/189/22 89/190/22 90/191/22
f 90/192/10 91/193/10 85/194/10 84/195/10
f 88/196/12 83/197/12 86/198/12 92/199/12
f 91/200/26 92/201/26 86/202/26 85/203/26
f 93/204/1 94/205/1 95/206/1 96/207/1
f 97/208/22 98/209/22 99/210/22 100/211/22
f 97/212/11 94/213/11 93/214/11 101/215/11
f 102/216/24 101/217/24 93/218/24 96/219/24
f 99/220/13 102/221/13 96/222/13 95/223/13
f 103/224/1 104/225/1 105/226/1 106/227/1
f 107/228/22 108/229/22 109/230/22 110/231/22
f 107/232/11 104/233/11 103/234/11 111/235/11
f 112/236/24 111/237/24 103/238/24 106/239/24
f 109/240/13 112/241/13 106/242/13 105/243/13
f 113/244/1 114/245/1 115/246/1 116/247/1
f 117/248/22 118/249/22 119/250/22 120/251/22
f 121/252/25 122/253/25 115/254/25 114/255/25
f 117/256/11 121/257/11 114/258/11 113/259/11
f 119/260/13 116/261/13 115/262/13 122/263/13
f 123/264/1 124/265/1 125/266/1 126/267/1
f 127/268/22 128/269/22 129/270/22 130/271/22
f 131/272/25 132/273/25 125/274/25 124/275/25
f 127/276/11 131/277/11 124/278/11 123/279/11
f 129/280/13 126/281/13 125/282/13 132/283/13
f 133/284/1 134/285/1 135/286/1 136/287/1
f 137/288/22 138/289/22 139/290/22 140/291/22
f 140/292/10 135/293/10 134/294/10 141/295/10
f 142/296/23 141/297/23 134/298/23 133/299/23
f 138/300/12 142/301/12 133/302/12 136/303/12
f 143/304/1 144/305/1 145/306/1 146/307/1
f 147/308/22 148/309/22 149/310/22 150/311/22
f 150/312/10 145/313/10 144/314/10 151/315/10
f 152/316/23 151/317/23 144/318/23 143/319/23
f 148/320/12 152/321/12 143/322/12 146/323/12
f 38/81/29 33/324/29 36/325/29 37/82/29
f 39/85/30 34/326/30 33/327/30 38/86/30
f 48/101/31 47/328/31 46/329/31 49/102/31
f 49/113/32 46/330/32 45/331/32 50/114/32
f 59/125/31 58/332/31 57/333/31 60/126/31
f 61/129/29 55/334/29 58/335/29 59/130/29
f 81/180/32 79/336/32 78/337/32 82/181/32
f 91/200/32 89/338/32 88/339/32 92/201/32
f 102/216/30 98/340/30 97/341/30 101/217/30
f 112/236/30 108/342/30 107/343/30 111/237/30
f 121/252/31 120/344/31 119/345/31 122/253/31
f 131/272/31 130/346/31 129/347/31 132/273/31
f 142/296/29 137/348/29 140/349/29 141/297/29
f 152/316/29 147/350/29 150/351/29 151/317/29
f 70/161/33 68/352/33 67/353/33 72/162/33
f 72/157/34 67/354/34 66/355/34 71/158/34
f 153/356/35 154/357/35 155/358/35
f 154/359/36 156/360/36 155/358/36
f 156/361/37 157/362/37 155/358/37
f 155/358/38 157/363/38 153/364/38
f 31/78/10 36/77/10 35/365/10
f 35/89/13 34/366/13 39/90/13
f 44/105/11 47/367/11 48/106/11
f 40/110/12 45/109/12 44/368/12
f 56/133/12 55/369/12 61/134/12
f 54/138/13 57/137/13 56/370/13
f 69/149/10 68/371/10 70/150/10
f 63/154/11 66/153/11 69/372/11
f 80/172/10 79/373/10 81/173/10
f 73/177/12 78/176/12 77/374/12
f 90/192/10 89/375/10 91/193/10
f 83/197/12 88/196/12 87/376/12
f 94/213/11 97/212/11 100/377/11
f 99/220/13 98/378/13 102/221/13
f 104/233/11 107/232/11 110/379/11
f 109/240/13 108/380/13 112/241/13
f 117/256/11 120/381/11 121/257/11
f 116/261/13 119/260/13 118/382/13
f 127/276/11 130/383/11 131/277/11
f 126/281/13 129/280/13 128/384/13
f 135/293/10 140/292/10 139/385/10
f 138/300/12 137/386/12 142/301/12
f 145/313/10 150/312/10 149/387/10
f 148/320/12 147/388/12 152/321/12

23015
assets/models/tree.obj Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,15 @@
#version 330 core
in vec4 frag_pos;
in vec4 frag_normal;
out vec4 output;
void main() {
vec4 ambient = vec4(0.0, 0.2, 0.46, 1.0);
vec4 light_location = vec4(0.0, 10.0, 20.0, 0.0);
vec4 light_color = vec4(0.1, 0.1, 0.2, 1.0);
vec4 light_distance = frag_pos - light_location;
float inverted_dot = -dot(frag_normal.xyz, light_distance.xyz);
output = ambient * light_color * inverted_dot;
}

View File

@ -1,14 +1,16 @@
#version 330 core
layout (location = 0) in vec3 pos;
layout (location = 1) in vec3 col;
layout (location = 1) in vec3 normal;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
out vec3 color;
out vec4 frag_pos;
out vec4 frag_normal;
void main() {
gl_Position = projection * view * model * vec4(pos.xyz, 1.0);
color = col;
frag_pos = gl_Position;
frag_normal = model * vec4(normal.xyz, 1.0);
}

134
main.c
View File

@ -1,24 +1,39 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <GL/glew.h>
#include <GL/freeglut.h>
#include <unistd.h>
#include <cglm/cglm.h>
#include <assimp/cimport.h>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
unsigned int vao;
unsigned int vbo;
unsigned int ebo;
unsigned int nbo;
unsigned int shader_program;
unsigned int vertex_shader;
unsigned int fragment_shader;
const char *vertex_shader_location = "../shader.vert";
const char *fragment_shader_location = "../shader.frag";
// shaders
const char *vertex_shader_location = "../assets/shaders/shader.vert";
const char *fragment_shader_location = "../assets/shaders/shader.frag";
float vertices[] = {
// positions // colors
0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom right
-0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, // bottom left
0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f // top
};
// GPU data
float *vertices = NULL;
unsigned int *indices = NULL;
float *normals = NULL;
long vertices_num = 0;
long indices_num = 0;
long normals_num = 0;
// Camera / LookAt
vec3 camera_position;
vec3 world_origin;
vec3 up;
vec3 right;
vec3 forward;
int load_shader(const char *path, unsigned int shader) {
FILE *fp = fopen(path, "r");
@ -72,6 +87,67 @@ int load_shader(const char *path, unsigned int shader) {
return 0;
}
int load_model(const char *path) {
const struct aiScene *scene = aiImportFile(path, aiProcess_Triangulate);
if (scene == NULL) {
return -1;
}
// allocate enough memory
vertices = (float *) malloc(1);
for (int mesh_index = 0; mesh_index < scene->mNumMeshes; mesh_index++) {
struct aiMesh *mesh = scene->mMeshes[mesh_index];
fprintf(stdout, "Number of vertices in mesh %d: %d\n", mesh_index, mesh->mNumVertices);
// fetch vertices
for (int vertex_index = 0; vertex_index < mesh->mNumVertices; vertex_index++) {
struct aiVector3D *vertex = &(mesh->mVertices[vertex_index]);
long start = vertices_num*3;
vertices_num++;
vertices = (float *) realloc(vertices, vertices_num*3*sizeof(float));
if (vertices == NULL) {
return -1;
}
memcpy(&vertices[start], vertex, sizeof(float)*3);
}
// fetch indices
for (int face_index = 0; face_index < mesh->mNumFaces; face_index++) {
struct aiFace *face = &(mesh->mFaces[face_index]);
long start = indices_num;
indices_num += face->mNumIndices;
indices = (unsigned int *) realloc(indices, sizeof(unsigned int)*indices_num);
if (indices == NULL) {
return -1;
}
memcpy(&indices[start], face->mIndices, sizeof(unsigned int)*face->mNumIndices);
}
// fetch normals
for (int normal_index = 0; normal_index < mesh->mNumVertices; normal_index++) {
struct aiVector3D *normal = &(mesh->mNormals[normal_index]);
long start = normals_num*3;
normals_num++;
normals = (float *) realloc(normals, normals_num*3*sizeof(float));
if (normals == NULL) {
return -1;
}
memcpy(&normals[start], normal, sizeof(float)*3);
}
}
aiReleaseImport(scene);
return 0;
}
int load_shaders() {
glDeleteProgram(shader_program);
shader_program = glCreateProgram();
@ -112,13 +188,13 @@ int load_shaders() {
return 0;
}
float degs = 0;
float deg = 0;
void display() {
mat4 model;
vec3 model_axis = {0.5f, 0.5f, 0.5f};
vec3 model_axis = {1.0f, 1.0f, 0.0f};
mat4 view;
vec3 view_translate = {0.0f, 0.0f, -3.0f};
vec3 view_translate = {0.0f, 0.0f, -10.0f};
mat4 projection;
GLint viewport[4]; // viewport: x, y, width, height
@ -126,15 +202,14 @@ void display() {
GLint view_uniform;
GLint projection_uniform;
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.13f, 0.13f, 0.13f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glGetIntegerv(GL_VIEWPORT, viewport);
glm_mat4_identity(model);
glm_rotate(model, glm_rad((float) degs ), model_axis);
degs += 0.01f;
glm_rotate(model, glm_rad((float)deg), model_axis);
deg += 1;
model_uniform = glGetUniformLocation(shader_program, "model");
glUniformMatrix4fv(model_uniform, 1, GL_FALSE, (float *) model);
@ -154,7 +229,7 @@ void display() {
glUseProgram(shader_program);
glBindVertexArray(vao);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDrawElements(GL_TRIANGLES, indices_num, GL_UNSIGNED_INT, (void *) 0);
glutSwapBuffers();
glutPostRedisplay();
@ -188,8 +263,15 @@ int setup() {
return -1;
}
if (load_model("assets/models/sphere.obj") == -1) {
fprintf(stderr, "Error: loading model\n");
return -1;
}
glGenVertexArrays(1, &vao);
glGenBuffers(1, &vbo);
glGenBuffers(1, &ebo);
glGenBuffers(1, &nbo);
return 0;
}
@ -198,20 +280,30 @@ void post_setup() {
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, 3*vertices_num*sizeof(float), vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*) 0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*) 0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void *) (3 * sizeof(float)));
glBindBuffer(GL_ARRAY_BUFFER, nbo);
glBufferData(GL_ARRAY_BUFFER, 3*normals_num*sizeof(float), normals, GL_STATIC_DRAW);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*) 0);
glEnableVertexAttribArray(1);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices_num*sizeof(unsigned int), indices, GL_STATIC_DRAW);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glEnable(GL_DEPTH_TEST);
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow("Simple Space Time Simulator");
GLenum err = glewInit();
if (err != GLEW_OK) {

View File

@ -1,8 +0,0 @@
#version 330 core
in vec3 color;
out vec4 output;
void main() {
output = vec4(color.xyz, 1.0f);
// output = vec4(1.0, 1.0, 1.0, 1.0);
}