Obj parser, plane is loading correctly with texcoords etc! now OS defines the bitmap layout and format
This commit is contained in:
48
assets/cube.obj
Normal file
48
assets/cube.obj
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
|
||||||
|
# cube.obj
|
||||||
|
#
|
||||||
|
|
||||||
|
mtllib cube.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
|
||||||
|
|
||||||
|
vt 1.000000 0.000000
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 1.000000 1.000000
|
||||||
|
vt 0.000000 1.000000
|
||||||
|
|
||||||
|
vn 0.000000 0.000000 1.000000
|
||||||
|
vn 0.000000 1.000000 0.000000
|
||||||
|
vn 0.000000 0.000000 -1.000000
|
||||||
|
vn 0.000000 -1.000000 0.000000
|
||||||
|
vn 1.000000 0.000000 0.000000
|
||||||
|
vn -1.000000 0.000000 0.000000
|
||||||
|
|
||||||
|
g cube
|
||||||
|
usemtl cube
|
||||||
|
s 1
|
||||||
|
f 1/1/1 2/2/1 3/3/1
|
||||||
|
f 3/3/1 2/2/1 4/4/1
|
||||||
|
s 2
|
||||||
|
f 3/1/2 4/2/2 5/3/2
|
||||||
|
f 5/3/2 4/2/2 6/4/2
|
||||||
|
s 3
|
||||||
|
f 5/4/3 6/3/3 7/2/3
|
||||||
|
f 7/2/3 6/3/3 8/1/3
|
||||||
|
s 4
|
||||||
|
f 7/1/4 8/2/4 1/3/4
|
||||||
|
f 1/3/4 8/2/4 2/4/4
|
||||||
|
s 5
|
||||||
|
f 2/1/5 8/2/5 4/3/5
|
||||||
|
f 4/3/5 8/2/5 6/4/5
|
||||||
|
s 6
|
||||||
|
f 7/1/6 1/2/6 5/3/6
|
||||||
|
f 5/3/6 1/2/6 3/4/6
|
||||||
BIN
assets/cube.png
Normal file
BIN
assets/cube.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 545 B |
707
assets/f22.obj
Normal file
707
assets/f22.obj
Normal file
@@ -0,0 +1,707 @@
|
|||||||
|
# Blender v2.79 (sub 0) OBJ File: 'fighters_0.blend'
|
||||||
|
# www.blender.org
|
||||||
|
mtllib f-22.mtl
|
||||||
|
o F-22
|
||||||
|
v 0.885739 0.001910 -0.380334
|
||||||
|
v 0.322026 0.035470 -0.433102
|
||||||
|
v -0.907053 0.017201 -0.352922
|
||||||
|
v 1.047128 0.048117 -0.183264
|
||||||
|
v 0.362277 0.114239 -0.142520
|
||||||
|
v 1.125941 0.131116 -0.101088
|
||||||
|
v 1.199510 0.242528 -0.056765
|
||||||
|
v 1.529867 0.098373 -0.067674
|
||||||
|
v 1.566378 0.011323 -0.146393
|
||||||
|
v 1.762624 0.050007 -0.049581
|
||||||
|
v 1.789931 -0.007335 -0.103633
|
||||||
|
v -1.226703 0.083896 -0.231401
|
||||||
|
v -1.226703 0.083896 -0.043034
|
||||||
|
v -1.304689 0.083896 -0.142520
|
||||||
|
v -0.560223 0.071221 -0.299735
|
||||||
|
v 0.779234 -0.185506 -0.231401
|
||||||
|
v -0.408812 -0.168000 -0.231401
|
||||||
|
v -1.226703 -0.023036 -0.043034
|
||||||
|
v -1.226703 -0.023036 -0.231464
|
||||||
|
v -1.304556 -0.023036 -0.142520
|
||||||
|
v -0.442164 -0.009523 -0.406435
|
||||||
|
v -0.875984 0.035470 -1.161559
|
||||||
|
v -0.727243 0.035470 -1.316844
|
||||||
|
v -0.494141 0.035470 -1.316844
|
||||||
|
v -1.376274 0.035470 -0.874979
|
||||||
|
v -1.417826 0.035470 -0.043034
|
||||||
|
v 1.016889 0.247035 -0.041089
|
||||||
|
v -0.910201 0.071705 -0.260759
|
||||||
|
v -0.910201 0.114239 -0.142520
|
||||||
|
v -1.347072 0.053931 -0.291132
|
||||||
|
v -0.949411 0.058716 -0.324121
|
||||||
|
v -1.086356 0.618995 -0.582384
|
||||||
|
v -0.945513 0.618995 -0.582384
|
||||||
|
v -0.820765 0.618995 -0.582384
|
||||||
|
v -1.074394 0.035470 -0.526090
|
||||||
|
v -1.347072 0.017010 -0.291132
|
||||||
|
v -1.420792 0.035470 -0.231401
|
||||||
|
v -1.704863 0.035470 -0.554642
|
||||||
|
v -1.607890 0.035470 -0.874979
|
||||||
|
v 1.142508 0.156204 -0.091107
|
||||||
|
v 0.821684 0.218761 -0.028011
|
||||||
|
v 1.453805 0.131564 -0.065163
|
||||||
|
v 0.835981 0.180467 -0.042103
|
||||||
|
v 0.885739 0.001910 0.380334
|
||||||
|
v 0.322026 0.035470 0.433102
|
||||||
|
v -0.907053 0.017201 0.352922
|
||||||
|
v 1.047128 0.048117 0.183264
|
||||||
|
v 0.362277 0.114239 0.142520
|
||||||
|
v 1.125941 0.131116 0.101088
|
||||||
|
v 1.199510 0.242528 0.056765
|
||||||
|
v 1.529867 0.098373 0.067674
|
||||||
|
v 1.566378 0.011323 0.146393
|
||||||
|
v 1.762624 0.050007 0.049581
|
||||||
|
v 1.789931 -0.007335 0.103633
|
||||||
|
v -1.226703 0.083896 0.231401
|
||||||
|
v -1.226703 0.083896 0.043034
|
||||||
|
v -1.304689 0.083896 0.142520
|
||||||
|
v -0.560223 0.071221 0.299735
|
||||||
|
v 0.779234 -0.185506 0.231401
|
||||||
|
v -0.408812 -0.168000 0.231401
|
||||||
|
v -1.226703 -0.023036 0.043034
|
||||||
|
v -1.226703 -0.023036 0.231464
|
||||||
|
v -1.304556 -0.023036 0.142520
|
||||||
|
v -0.442164 -0.009523 0.406435
|
||||||
|
v -0.875984 0.035470 1.161559
|
||||||
|
v -0.727243 0.035470 1.316844
|
||||||
|
v -0.494141 0.035470 1.316844
|
||||||
|
v -1.376274 0.035470 0.874979
|
||||||
|
v -1.417826 0.035470 0.043034
|
||||||
|
v 1.016889 0.247035 0.041089
|
||||||
|
v -0.910201 0.071705 0.260759
|
||||||
|
v -0.910201 0.114239 0.142520
|
||||||
|
v -1.347072 0.053931 0.291132
|
||||||
|
v -0.949411 0.058716 0.324121
|
||||||
|
v -1.086356 0.618995 0.582384
|
||||||
|
v -0.945513 0.618995 0.582384
|
||||||
|
v -0.820765 0.618995 0.582384
|
||||||
|
v -1.074394 0.035470 0.526090
|
||||||
|
v -1.347072 0.017010 0.291132
|
||||||
|
v -1.420792 0.035470 0.231401
|
||||||
|
v -1.704863 0.035470 0.554642
|
||||||
|
v -1.607890 0.035470 0.874979
|
||||||
|
v 1.142508 0.156204 0.091107
|
||||||
|
v 0.821684 0.218761 0.028011
|
||||||
|
v 1.453805 0.131564 0.065163
|
||||||
|
v 0.835981 0.180467 0.042103
|
||||||
|
v -0.910201 0.094558 0.000000
|
||||||
|
v 0.403590 0.158204 0.000000
|
||||||
|
v 1.236021 0.268974 0.000000
|
||||||
|
v 1.568094 0.113851 0.000000
|
||||||
|
v 1.791648 0.062518 0.000000
|
||||||
|
v 2.014232 -0.030625 0.000000
|
||||||
|
v 1.566378 -0.120168 0.000000
|
||||||
|
v 1.789931 -0.082458 0.000000
|
||||||
|
v 0.919486 -0.169810 0.000000
|
||||||
|
v -0.408812 -0.167592 0.000000
|
||||||
|
v -1.226703 0.078200 0.000000
|
||||||
|
v -1.226703 -0.023036 0.000000
|
||||||
|
v -1.442453 0.035470 0.000000
|
||||||
|
v 1.016889 0.266178 0.000000
|
||||||
|
v 1.487051 0.151710 0.000000
|
||||||
|
v 0.817113 0.231006 0.000000
|
||||||
|
vt 0.302940 0.699066
|
||||||
|
vt 0.442081 0.762279
|
||||||
|
vt 0.260042 0.751449
|
||||||
|
vt 0.780315 0.800162
|
||||||
|
vt 0.431099 0.800162
|
||||||
|
vt 0.239093 0.773292
|
||||||
|
vt 0.316239 0.628907
|
||||||
|
vt 0.320312 0.648438
|
||||||
|
vt 0.269531 0.648438
|
||||||
|
vt 0.268080 0.668033
|
||||||
|
vt 0.209833 0.668033
|
||||||
|
vt 0.152344 0.648438
|
||||||
|
vt 0.218750 0.648438
|
||||||
|
vt 0.234686 0.622186
|
||||||
|
vt 0.122021 0.761249
|
||||||
|
vt 0.069858 0.786983
|
||||||
|
vt 0.062599 0.772615
|
||||||
|
vt 0.121565 0.800162
|
||||||
|
vt 0.131726 0.782173
|
||||||
|
vt 0.002978 0.800162
|
||||||
|
vt 0.062143 0.800162
|
||||||
|
vt 0.687288 0.720490
|
||||||
|
vt 0.780315 0.762279
|
||||||
|
vt 0.117476 0.888175
|
||||||
|
vt 0.176898 0.858183
|
||||||
|
vt 0.176898 0.893135
|
||||||
|
vt 0.057855 0.881984
|
||||||
|
vt 0.117476 0.868207
|
||||||
|
vt 0.314919 0.902915
|
||||||
|
vt 0.348847 0.844988
|
||||||
|
vt 0.350939 0.448650
|
||||||
|
vt 0.338144 0.510748
|
||||||
|
vt 0.289431 0.452822
|
||||||
|
vt 0.329981 0.132766
|
||||||
|
vt 0.645773 0.071258
|
||||||
|
vt 0.645773 0.132766
|
||||||
|
vt 0.452780 0.685040
|
||||||
|
vt 0.669723 0.450134
|
||||||
|
vt 0.731683 0.450134
|
||||||
|
vt 0.771220 0.491410
|
||||||
|
vt 0.823959 0.660323
|
||||||
|
vt 0.507656 0.899553
|
||||||
|
vt 0.357817 0.890633
|
||||||
|
vt 0.386127 0.840816
|
||||||
|
vt 0.701919 0.845469
|
||||||
|
vt 0.896439 0.722777
|
||||||
|
vt 0.916034 0.738294
|
||||||
|
vt 0.864444 0.738294
|
||||||
|
vt 0.445843 0.497454
|
||||||
|
vt 0.469468 0.469031
|
||||||
|
vt 0.469468 0.497454
|
||||||
|
vt 0.495912 0.497454
|
||||||
|
vt 0.654638 0.182832
|
||||||
|
vt 0.668454 0.424826
|
||||||
|
vt 0.451511 0.189920
|
||||||
|
vt 0.654638 0.179292
|
||||||
|
vt 0.778209 0.165068
|
||||||
|
vt 0.822690 0.211097
|
||||||
|
vt 0.864444 0.469031
|
||||||
|
vt 0.864444 0.497454
|
||||||
|
vt 0.916034 0.484582
|
||||||
|
vt 0.863174 0.082019
|
||||||
|
vt 0.863174 0.071258
|
||||||
|
vt 0.913977 0.082019
|
||||||
|
vt 0.864444 0.800162
|
||||||
|
vt 0.864444 0.789083
|
||||||
|
vt 0.809306 0.497454
|
||||||
|
vt 0.809306 0.469031
|
||||||
|
vt 0.860108 0.484582
|
||||||
|
vt 0.915246 0.789083
|
||||||
|
vt 0.921792 0.800162
|
||||||
|
vt 0.822690 0.214637
|
||||||
|
vt 0.769951 0.383550
|
||||||
|
vt 0.730414 0.424826
|
||||||
|
vt 0.834355 0.894697
|
||||||
|
vt 0.919320 0.884002
|
||||||
|
vt 0.141653 0.276624
|
||||||
|
vt 0.107458 0.425551
|
||||||
|
vt 0.038204 0.279948
|
||||||
|
vt 0.178054 0.425551
|
||||||
|
vt 0.140617 0.425551
|
||||||
|
vt 0.883868 0.109141
|
||||||
|
vt 0.863174 0.132783
|
||||||
|
vt 0.780315 0.730850
|
||||||
|
vt 0.904201 0.567586
|
||||||
|
vt 0.790737 0.714008
|
||||||
|
vt 0.991542 0.652734
|
||||||
|
vt 0.385137 0.280077
|
||||||
|
vt 0.361364 0.425551
|
||||||
|
vt 0.394523 0.425551
|
||||||
|
vt 0.431960 0.425551
|
||||||
|
vt 0.501261 0.275352
|
||||||
|
vt 0.895170 0.148643
|
||||||
|
vt 0.914765 0.132766
|
||||||
|
vt 0.902932 0.303834
|
||||||
|
vt 0.990273 0.218686
|
||||||
|
vt 0.964497 0.303834
|
||||||
|
vt 0.965766 0.567586
|
||||||
|
vt 0.885173 0.762279
|
||||||
|
vt 0.151941 0.583698
|
||||||
|
vt 0.239090 0.583579
|
||||||
|
vt 0.234686 0.590248
|
||||||
|
vt 0.316239 0.596969
|
||||||
|
vt 0.431096 0.590779
|
||||||
|
vt 0.321182 0.614322
|
||||||
|
vt 0.319967 0.606876
|
||||||
|
vt 0.431099 0.614322
|
||||||
|
vt 0.143107 0.601016
|
||||||
|
vt 0.131726 0.583028
|
||||||
|
vt 0.321182 0.668033
|
||||||
|
vt 0.121565 0.601016
|
||||||
|
vt 0.131723 0.574876
|
||||||
|
vt 0.292110 0.279948
|
||||||
|
vt 0.247354 0.275352
|
||||||
|
vt 0.710784 0.887594
|
||||||
|
vt 0.920523 0.071258
|
||||||
|
vt 0.495912 0.469031
|
||||||
|
vt 0.445826 0.469031
|
||||||
|
vt 0.292701 0.071258
|
||||||
|
vt 0.390527 0.498466
|
||||||
|
vt 0.143107 0.668033
|
||||||
|
vt 0.302940 0.699066
|
||||||
|
vt 0.260042 0.751449
|
||||||
|
vt 0.442081 0.762279
|
||||||
|
vt 0.239093 0.773292
|
||||||
|
vt 0.316239 0.628907
|
||||||
|
vt 0.269531 0.648438
|
||||||
|
vt 0.320312 0.648438
|
||||||
|
vt 0.218750 0.648438
|
||||||
|
vt 0.152344 0.648438
|
||||||
|
vt 0.234686 0.622186
|
||||||
|
vt 0.122021 0.761249
|
||||||
|
vt 0.062599 0.772615
|
||||||
|
vt 0.069858 0.786983
|
||||||
|
vt 0.131726 0.782173
|
||||||
|
vt 0.687288 0.720490
|
||||||
|
vt 0.780315 0.762279
|
||||||
|
vt 0.117476 0.888175
|
||||||
|
vt 0.176898 0.893135
|
||||||
|
vt 0.314919 0.902915
|
||||||
|
vt 0.350939 0.448650
|
||||||
|
vt 0.338144 0.510748
|
||||||
|
vt 0.329981 0.132766
|
||||||
|
vt 0.645773 0.132766
|
||||||
|
vt 0.452780 0.685040
|
||||||
|
vt 0.731683 0.450134
|
||||||
|
vt 0.669723 0.450134
|
||||||
|
vt 0.823959 0.660323
|
||||||
|
vt 0.771220 0.491410
|
||||||
|
vt 0.507656 0.899553
|
||||||
|
vt 0.386127 0.840816
|
||||||
|
vt 0.357817 0.890633
|
||||||
|
vt 0.701919 0.845469
|
||||||
|
vt 0.896439 0.722777
|
||||||
|
vt 0.864444 0.738294
|
||||||
|
vt 0.916034 0.738294
|
||||||
|
vt 0.445843 0.497454
|
||||||
|
vt 0.469468 0.497454
|
||||||
|
vt 0.469468 0.469031
|
||||||
|
vt 0.495912 0.497454
|
||||||
|
vt 0.654638 0.182832
|
||||||
|
vt 0.451511 0.189920
|
||||||
|
vt 0.668454 0.424826
|
||||||
|
vt 0.654638 0.179292
|
||||||
|
vt 0.822690 0.211097
|
||||||
|
vt 0.778209 0.165068
|
||||||
|
vt 0.864444 0.469031
|
||||||
|
vt 0.916034 0.484582
|
||||||
|
vt 0.864444 0.497454
|
||||||
|
vt 0.863174 0.082019
|
||||||
|
vt 0.913977 0.082019
|
||||||
|
vt 0.864444 0.789083
|
||||||
|
vt 0.809306 0.497454
|
||||||
|
vt 0.860108 0.484582
|
||||||
|
vt 0.809306 0.469031
|
||||||
|
vt 0.915246 0.789083
|
||||||
|
vt 0.822690 0.214637
|
||||||
|
vt 0.769951 0.383550
|
||||||
|
vt 0.730414 0.424826
|
||||||
|
vt 0.834355 0.894697
|
||||||
|
vt 0.919320 0.884002
|
||||||
|
vt 0.141653 0.276624
|
||||||
|
vt 0.038204 0.279948
|
||||||
|
vt 0.107458 0.425551
|
||||||
|
vt 0.140617 0.425551
|
||||||
|
vt 0.178054 0.425551
|
||||||
|
vt 0.883868 0.109141
|
||||||
|
vt 0.863174 0.132783
|
||||||
|
vt 0.780315 0.730850
|
||||||
|
vt 0.904201 0.567586
|
||||||
|
vt 0.790737 0.714008
|
||||||
|
vt 0.991542 0.652734
|
||||||
|
vt 0.385137 0.280077
|
||||||
|
vt 0.394523 0.425551
|
||||||
|
vt 0.361364 0.425551
|
||||||
|
vt 0.501261 0.275352
|
||||||
|
vt 0.431960 0.425551
|
||||||
|
vt 0.895170 0.148643
|
||||||
|
vt 0.914765 0.132766
|
||||||
|
vt 0.902932 0.303834
|
||||||
|
vt 0.964497 0.303834
|
||||||
|
vt 0.990273 0.218686
|
||||||
|
vt 0.965766 0.567586
|
||||||
|
vt 0.885173 0.762279
|
||||||
|
vt 0.151941 0.583698
|
||||||
|
vt 0.234686 0.590248
|
||||||
|
vt 0.239090 0.583579
|
||||||
|
vt 0.316239 0.596969
|
||||||
|
vt 0.319967 0.606876
|
||||||
|
vt 0.131726 0.583028
|
||||||
|
vt 0.131723 0.574876
|
||||||
|
vt 0.292110 0.279948
|
||||||
|
vt 0.247354 0.275352
|
||||||
|
vt 0.710784 0.887594
|
||||||
|
vt 0.495912 0.469031
|
||||||
|
vt 0.445826 0.469031
|
||||||
|
vt 0.390527 0.498466
|
||||||
|
vn 0.0752 0.9554 -0.2856
|
||||||
|
vn -0.0464 0.9582 -0.2821
|
||||||
|
vn -0.0672 0.7335 -0.6764
|
||||||
|
vn -0.1079 0.3076 -0.9454
|
||||||
|
vn -0.1576 0.8951 -0.4170
|
||||||
|
vn 0.3158 0.7660 -0.5600
|
||||||
|
vn 0.1032 0.3081 -0.9457
|
||||||
|
vn 0.0996 0.6507 -0.7527
|
||||||
|
vn 0.1879 0.7196 -0.6685
|
||||||
|
vn 0.2166 0.9180 -0.3323
|
||||||
|
vn 0.3493 0.7254 -0.5931
|
||||||
|
vn 0.3509 0.8385 -0.4170
|
||||||
|
vn 0.0000 0.9645 -0.2639
|
||||||
|
vn 0.0656 -0.7424 -0.6668
|
||||||
|
vn 0.1839 -0.7958 -0.5769
|
||||||
|
vn 0.0506 -0.6600 -0.7496
|
||||||
|
vn 0.6508 -0.6744 -0.3487
|
||||||
|
vn -0.0147 -0.9999 0.0018
|
||||||
|
vn -0.0004 0.9652 -0.2616
|
||||||
|
vn 0.0000 0.9994 -0.0351
|
||||||
|
vn -0.0610 0.9980 -0.0190
|
||||||
|
vn 0.0346 -0.6338 -0.7728
|
||||||
|
vn -0.0101 -0.6854 -0.7281
|
||||||
|
vn -0.2421 0.9703 0.0011
|
||||||
|
vn -0.7517 -0.0009 -0.6595
|
||||||
|
vn -0.7870 -0.0010 0.6169
|
||||||
|
vn 0.0569 -0.9970 -0.0525
|
||||||
|
vn -0.0625 -0.9970 -0.0448
|
||||||
|
vn 0.0001 -0.0006 1.0000
|
||||||
|
vn -0.0313 0.9991 -0.0300
|
||||||
|
vn -0.1740 -0.9847 0.0000
|
||||||
|
vn -0.2927 -0.9562 0.0000
|
||||||
|
vn -0.0512 0.9901 0.1310
|
||||||
|
vn 0.0000 0.0000 -1.0000
|
||||||
|
vn -0.1931 0.9749 -0.1105
|
||||||
|
vn -0.0670 -0.9975 -0.0209
|
||||||
|
vn -0.0388 -0.9986 -0.0372
|
||||||
|
vn -0.1372 -0.7744 -0.6176
|
||||||
|
vn 0.0702 -0.4308 -0.8997
|
||||||
|
vn 0.0000 -0.4186 -0.9082
|
||||||
|
vn -0.1725 -0.9734 -0.1510
|
||||||
|
vn -0.1596 -0.9872 0.0017
|
||||||
|
vn -0.1795 -0.9737 0.1405
|
||||||
|
vn 0.0048 0.9410 -0.3385
|
||||||
|
vn 0.0000 0.9906 0.1368
|
||||||
|
vn 0.0387 0.9987 -0.0335
|
||||||
|
vn -0.0258 0.9948 -0.0985
|
||||||
|
vn -0.0061 0.8987 -0.4386
|
||||||
|
vn -0.0204 0.9946 -0.1018
|
||||||
|
vn -0.1436 0.9816 0.1262
|
||||||
|
vn 0.0000 0.5067 0.8621
|
||||||
|
vn -0.0803 0.4857 0.8704
|
||||||
|
vn -0.2881 -0.9557 -0.0602
|
||||||
|
vn 0.0387 -0.9987 -0.0335
|
||||||
|
vn -0.0421 -0.9990 -0.0128
|
||||||
|
vn -0.0126 -0.9956 -0.0929
|
||||||
|
vn -0.0646 -0.8840 -0.4629
|
||||||
|
vn -0.0000 0.9995 -0.0316
|
||||||
|
vn 0.0000 -0.9995 -0.0316
|
||||||
|
vn -0.0766 0.9953 0.0600
|
||||||
|
vn -0.0765 0.9948 -0.0671
|
||||||
|
vn -0.0519 0.9893 0.1366
|
||||||
|
vn -0.1094 0.4290 -0.8967
|
||||||
|
vn 0.3481 0.8307 -0.4344
|
||||||
|
vn -0.0681 0.4073 -0.9107
|
||||||
|
vn -0.1215 0.3445 -0.9309
|
||||||
|
vn -0.0116 0.9064 -0.4223
|
||||||
|
vn -0.0132 0.9096 -0.4153
|
||||||
|
vn 0.3865 0.8274 -0.4075
|
||||||
|
vn -0.1436 -0.9816 0.1262
|
||||||
|
vn 0.0970 0.4924 0.8649
|
||||||
|
vn -0.0421 0.9990 -0.0128
|
||||||
|
vn -0.0694 -0.4316 -0.8994
|
||||||
|
vn -0.1182 -0.7472 -0.6540
|
||||||
|
vn -0.2436 0.9615 0.1273
|
||||||
|
vn -0.2588 -0.9545 -0.1481
|
||||||
|
vn 0.0000 -0.9988 -0.0494
|
||||||
|
vn -0.7875 0.0000 0.6163
|
||||||
|
vn -0.7525 0.0004 -0.6586
|
||||||
|
vn 0.0200 -0.7392 -0.6731
|
||||||
|
vn 0.0355 0.9988 -0.0328
|
||||||
|
vn -0.0017 -0.9976 0.0687
|
||||||
|
vn 0.6468 -0.6647 -0.3739
|
||||||
|
vn -0.0053 -0.7439 -0.6682
|
||||||
|
vn 0.1353 -0.8022 -0.5815
|
||||||
|
vn -0.0364 0.9403 -0.3383
|
||||||
|
vn 0.2094 0.9120 -0.3527
|
||||||
|
vn 0.1990 0.7019 -0.6839
|
||||||
|
vn 0.1150 0.6924 -0.7123
|
||||||
|
vn 0.3792 0.8117 -0.4444
|
||||||
|
vn 0.0728 0.9469 -0.3132
|
||||||
|
vn 0.0825 0.9589 -0.2714
|
||||||
|
vn 0.0752 0.9554 0.2856
|
||||||
|
vn -0.0464 0.9582 0.2821
|
||||||
|
vn -0.0672 0.7335 0.6764
|
||||||
|
vn -0.1079 0.3076 0.9454
|
||||||
|
vn -0.1576 0.8951 0.4170
|
||||||
|
vn 0.3158 0.7660 0.5600
|
||||||
|
vn 0.1032 0.3081 0.9457
|
||||||
|
vn 0.0996 0.6507 0.7527
|
||||||
|
vn 0.1879 0.7196 0.6685
|
||||||
|
vn 0.2166 0.9180 0.3323
|
||||||
|
vn 0.3493 0.7254 0.5931
|
||||||
|
vn 0.3509 0.8385 0.4170
|
||||||
|
vn 0.0000 0.9645 0.2639
|
||||||
|
vn 0.0656 -0.7424 0.6668
|
||||||
|
vn 0.1839 -0.7958 0.5769
|
||||||
|
vn 0.0506 -0.6600 0.7496
|
||||||
|
vn 0.6508 -0.6744 0.3487
|
||||||
|
vn -0.0147 -0.9999 -0.0018
|
||||||
|
vn -0.0004 0.9652 0.2616
|
||||||
|
vn 0.0000 0.9994 0.0351
|
||||||
|
vn -0.0610 0.9980 0.0190
|
||||||
|
vn 0.0346 -0.6338 0.7728
|
||||||
|
vn -0.0101 -0.6854 0.7281
|
||||||
|
vn -0.2421 0.9703 -0.0011
|
||||||
|
vn -0.7517 -0.0009 0.6595
|
||||||
|
vn -0.7870 -0.0010 -0.6169
|
||||||
|
vn 0.0569 -0.9970 0.0525
|
||||||
|
vn -0.0625 -0.9970 0.0448
|
||||||
|
vn 0.0001 -0.0006 -1.0000
|
||||||
|
vn -0.0313 0.9991 0.0300
|
||||||
|
vn -0.0512 0.9901 -0.1310
|
||||||
|
vn 0.0000 0.0000 1.0000
|
||||||
|
vn -0.1931 0.9749 0.1105
|
||||||
|
vn -0.0670 -0.9975 0.0209
|
||||||
|
vn -0.0388 -0.9986 0.0372
|
||||||
|
vn -0.1372 -0.7744 0.6176
|
||||||
|
vn 0.0702 -0.4308 0.8997
|
||||||
|
vn 0.0000 -0.4186 0.9082
|
||||||
|
vn -0.1725 -0.9734 0.1510
|
||||||
|
vn -0.1596 -0.9872 -0.0017
|
||||||
|
vn -0.1795 -0.9737 -0.1405
|
||||||
|
vn 0.0048 0.9410 0.3385
|
||||||
|
vn 0.0000 0.9906 -0.1368
|
||||||
|
vn 0.0387 0.9987 0.0335
|
||||||
|
vn -0.0258 0.9948 0.0985
|
||||||
|
vn -0.0061 0.8987 0.4386
|
||||||
|
vn -0.0204 0.9946 0.1018
|
||||||
|
vn -0.1436 0.9816 -0.1262
|
||||||
|
vn 0.0000 0.5067 -0.8621
|
||||||
|
vn -0.0803 0.4857 -0.8704
|
||||||
|
vn -0.2881 -0.9557 0.0602
|
||||||
|
vn 0.0387 -0.9987 0.0335
|
||||||
|
vn -0.0421 -0.9990 0.0128
|
||||||
|
vn -0.0126 -0.9956 0.0929
|
||||||
|
vn -0.0646 -0.8840 0.4629
|
||||||
|
vn -0.0000 0.9995 0.0316
|
||||||
|
vn 0.0000 -0.9995 0.0316
|
||||||
|
vn -0.0766 0.9953 -0.0600
|
||||||
|
vn -0.0765 0.9948 0.0671
|
||||||
|
vn -0.0519 0.9893 -0.1366
|
||||||
|
vn -0.1094 0.4290 0.8967
|
||||||
|
vn 0.3481 0.8307 0.4344
|
||||||
|
vn -0.0681 0.4073 0.9107
|
||||||
|
vn -0.1215 0.3445 0.9309
|
||||||
|
vn -0.0116 0.9064 0.4223
|
||||||
|
vn -0.0132 0.9096 0.4153
|
||||||
|
vn 0.3865 0.8274 0.4075
|
||||||
|
vn -0.1436 -0.9816 -0.1262
|
||||||
|
vn 0.0970 0.4924 -0.8649
|
||||||
|
vn -0.0421 0.9990 0.0128
|
||||||
|
vn -0.0694 -0.4316 0.8994
|
||||||
|
vn -0.1182 -0.7472 0.6540
|
||||||
|
vn -0.2436 0.9615 -0.1273
|
||||||
|
vn -0.2588 -0.9545 0.1481
|
||||||
|
vn 0.0000 -0.9988 0.0494
|
||||||
|
vn -0.7875 0.0000 -0.6163
|
||||||
|
vn -0.7525 0.0004 0.6586
|
||||||
|
vn 0.0200 -0.7392 0.6731
|
||||||
|
vn 0.0355 0.9988 0.0328
|
||||||
|
vn -0.0017 -0.9976 -0.0687
|
||||||
|
vn 0.6468 -0.6647 0.3739
|
||||||
|
vn -0.0053 -0.7439 0.6682
|
||||||
|
vn 0.1353 -0.8022 0.5815
|
||||||
|
vn -0.0364 0.9403 0.3383
|
||||||
|
vn 0.2094 0.9120 0.3527
|
||||||
|
vn 0.1990 0.7019 0.6839
|
||||||
|
vn 0.1150 0.6924 0.7123
|
||||||
|
vn 0.3792 0.8117 0.4444
|
||||||
|
vn 0.0728 0.9469 0.3132
|
||||||
|
vn 0.0825 0.9589 0.2714
|
||||||
|
usemtl Material.001
|
||||||
|
s off
|
||||||
|
f 1/1/1 5/2/1 4/3/1
|
||||||
|
f 5/2/2 87/4/2 88/5/2
|
||||||
|
f 4/3/3 88/5/3 6/6/3
|
||||||
|
f 43/7/4 41/8/4 27/9/4
|
||||||
|
f 41/8/5 100/10/5 27/9/5
|
||||||
|
f 89/11/6 42/12/6 7/13/6
|
||||||
|
f 7/13/7 42/12/7 40/14/7
|
||||||
|
f 6/6/8 9/15/8 4/3/8
|
||||||
|
f 9/15/9 10/16/9 11/17/9
|
||||||
|
f 90/18/10 10/16/10 8/19/10
|
||||||
|
f 11/17/11 10/16/11 92/20/11
|
||||||
|
f 10/16/12 91/21/12 92/20/12
|
||||||
|
f 15/22/13 29/23/13 5/2/13
|
||||||
|
f 11/24/14 93/25/14 9/26/14
|
||||||
|
f 11/24/15 92/27/15 94/28/15
|
||||||
|
f 4/29/16 93/25/16 95/30/16
|
||||||
|
f 16/31/17 4/32/17 95/33/17
|
||||||
|
f 16/34/18 96/35/18 17/36/18
|
||||||
|
f 5/2/19 2/37/19 15/22/19
|
||||||
|
f 15/22/20 24/38/20 23/39/20
|
||||||
|
f 15/22/21 22/40/21 35/41/21
|
||||||
|
f 2/42/22 1/43/22 16/44/22
|
||||||
|
f 17/45/23 2/42/23 16/44/23
|
||||||
|
f 30/46/24 37/47/24 12/48/24
|
||||||
|
f 12/49/25 20/50/25 14/51/25
|
||||||
|
f 20/50/26 13/52/26 14/51/26
|
||||||
|
f 21/53/27 24/54/27 2/55/27
|
||||||
|
f 21/56/28 3/57/28 35/58/28
|
||||||
|
f 19/59/29 12/60/29 37/61/29
|
||||||
|
f 15/22/30 23/39/30 22/40/30
|
||||||
|
f 18/62/31 96/35/31 98/63/31
|
||||||
|
f 98/63/32 26/64/32 18/62/32
|
||||||
|
f 97/65/33 87/4/33 13/66/33
|
||||||
|
f 13/67/34 18/68/34 26/69/34
|
||||||
|
f 97/65/35 26/70/35 99/71/35
|
||||||
|
f 35/72/36 22/73/36 21/53/36
|
||||||
|
f 22/73/37 23/74/37 21/53/37
|
||||||
|
f 3/75/38 17/45/38 19/76/38
|
||||||
|
f 31/77/39 34/78/39 15/79/39
|
||||||
|
f 31/77/40 32/80/40 33/81/40
|
||||||
|
f 20/82/41 19/83/41 17/36/41
|
||||||
|
f 20/82/42 17/36/42 96/35/42
|
||||||
|
f 18/62/43 20/82/43 96/35/43
|
||||||
|
f 29/23/44 28/84/44 12/48/44
|
||||||
|
f 87/4/45 5/2/45 29/23/45
|
||||||
|
f 25/85/46 30/46/46 35/41/46
|
||||||
|
f 31/86/47 15/22/47 35/41/47
|
||||||
|
f 30/46/48 12/48/48 28/84/48
|
||||||
|
f 30/46/49 31/86/49 35/41/49
|
||||||
|
f 30/46/50 38/87/50 37/47/50
|
||||||
|
f 28/88/51 34/89/51 33/90/51
|
||||||
|
f 28/88/52 32/91/52 30/92/52
|
||||||
|
f 36/93/53 19/83/53 37/94/53
|
||||||
|
f 36/93/54 25/95/54 35/58/54
|
||||||
|
f 36/93/55 38/96/55 39/97/55
|
||||||
|
f 36/93/56 35/58/56 3/57/56
|
||||||
|
f 3/57/57 19/83/57 36/93/57
|
||||||
|
f 25/85/58 39/98/58 30/46/58
|
||||||
|
f 36/93/59 39/97/59 25/95/59
|
||||||
|
f 29/23/60 14/99/60 13/66/60
|
||||||
|
f 14/99/61 29/23/61 12/48/61
|
||||||
|
f 87/4/62 29/23/62 13/66/62
|
||||||
|
f 42/100/7 6/101/7 40/102/7
|
||||||
|
f 43/103/63 6/101/63 88/104/63
|
||||||
|
f 102/105/5 41/106/5 88/107/5
|
||||||
|
f 101/108/64 8/109/64 42/100/64
|
||||||
|
f 27/9/65 7/13/65 40/14/65
|
||||||
|
f 40/14/66 43/7/66 27/9/66
|
||||||
|
f 41/8/5 102/110/5 100/10/5
|
||||||
|
f 100/10/67 89/11/67 27/9/67
|
||||||
|
f 89/11/68 7/13/68 27/9/68
|
||||||
|
f 101/108/69 90/111/69 8/109/69
|
||||||
|
f 43/103/63 40/102/63 6/101/63
|
||||||
|
f 88/104/4 41/106/4 43/103/4
|
||||||
|
f 42/100/7 8/112/7 6/101/7
|
||||||
|
f 36/93/70 37/94/70 38/96/70
|
||||||
|
f 28/88/51 33/90/51 32/91/51
|
||||||
|
f 28/88/71 15/113/71 34/89/71
|
||||||
|
f 30/46/72 39/98/72 38/87/72
|
||||||
|
f 31/77/73 30/114/73 32/80/73
|
||||||
|
f 31/77/40 33/81/40 34/78/40
|
||||||
|
f 3/75/74 21/115/74 17/45/74
|
||||||
|
f 97/65/75 13/66/75 26/70/75
|
||||||
|
f 98/63/76 99/116/76 26/64/76
|
||||||
|
f 21/53/77 23/74/77 24/54/77
|
||||||
|
f 20/50/78 18/117/78 13/52/78
|
||||||
|
f 12/49/79 19/118/79 20/50/79
|
||||||
|
f 17/45/80 21/115/80 2/42/80
|
||||||
|
f 15/22/81 2/37/81 24/38/81
|
||||||
|
f 16/34/82 95/119/82 96/35/82
|
||||||
|
f 16/31/83 1/120/83 4/32/83
|
||||||
|
f 4/29/84 9/26/84 93/25/84
|
||||||
|
f 11/24/85 94/28/85 93/25/85
|
||||||
|
f 15/22/86 28/84/86 29/23/86
|
||||||
|
f 90/18/87 91/21/87 10/16/87
|
||||||
|
f 9/15/88 8/19/88 10/16/88
|
||||||
|
f 6/6/89 8/19/89 9/15/89
|
||||||
|
f 89/11/90 101/121/90 42/12/90
|
||||||
|
f 4/3/91 5/2/91 88/5/91
|
||||||
|
f 1/1/92 2/37/92 5/2/92
|
||||||
|
f 44/122/93 47/123/93 48/124/93
|
||||||
|
f 48/124/94 88/5/94 87/4/94
|
||||||
|
f 47/123/95 49/125/95 88/5/95
|
||||||
|
f 86/126/96 70/127/96 84/128/96
|
||||||
|
f 84/128/97 70/127/97 100/10/97
|
||||||
|
f 89/11/98 50/129/98 85/130/98
|
||||||
|
f 50/129/99 83/131/99 85/130/99
|
||||||
|
f 49/125/100 47/123/100 52/132/100
|
||||||
|
f 52/132/101 54/133/101 53/134/101
|
||||||
|
f 90/18/102 51/135/102 53/134/102
|
||||||
|
f 54/133/103 92/20/103 53/134/103
|
||||||
|
f 53/134/104 92/20/104 91/21/104
|
||||||
|
f 58/136/105 48/124/105 72/137/105
|
||||||
|
f 54/138/106 52/139/106 93/25/106
|
||||||
|
f 54/138/107 94/28/107 92/27/107
|
||||||
|
f 47/140/108 95/30/108 93/25/108
|
||||||
|
f 59/141/109 95/33/109 47/142/109
|
||||||
|
f 59/143/110 60/144/110 96/35/110
|
||||||
|
f 48/124/111 58/136/111 45/145/111
|
||||||
|
f 58/136/112 66/146/112 67/147/112
|
||||||
|
f 58/136/113 78/148/113 65/149/113
|
||||||
|
f 45/150/114 59/151/114 44/152/114
|
||||||
|
f 60/153/115 59/151/115 45/150/115
|
||||||
|
f 73/154/116 55/155/116 80/156/116
|
||||||
|
f 55/157/117 57/158/117 63/159/117
|
||||||
|
f 63/159/118 57/158/118 56/160/118
|
||||||
|
f 64/161/119 45/162/119 67/163/119
|
||||||
|
f 64/164/120 78/165/120 46/166/120
|
||||||
|
f 62/167/121 80/168/121 55/169/121
|
||||||
|
f 58/136/122 65/149/122 66/146/122
|
||||||
|
f 61/170/31 98/63/31 96/35/31
|
||||||
|
f 98/63/32 61/170/32 69/171/32
|
||||||
|
f 97/65/123 56/172/123 87/4/123
|
||||||
|
f 56/173/124 69/174/124 61/175/124
|
||||||
|
f 97/65/125 99/71/125 69/176/125
|
||||||
|
f 78/177/126 64/161/126 65/178/126
|
||||||
|
f 65/178/127 64/161/127 66/179/127
|
||||||
|
f 46/180/128 62/181/128 60/153/128
|
||||||
|
f 74/182/129 58/183/129 77/184/129
|
||||||
|
f 74/182/130 76/185/130 75/186/130
|
||||||
|
f 63/187/131 60/144/131 62/188/131
|
||||||
|
f 63/187/132 96/35/132 60/144/132
|
||||||
|
f 61/170/133 96/35/133 63/187/133
|
||||||
|
f 72/137/134 55/155/134 71/189/134
|
||||||
|
f 87/4/135 72/137/135 48/124/135
|
||||||
|
f 68/190/136 78/148/136 73/154/136
|
||||||
|
f 74/191/137 78/148/137 58/136/137
|
||||||
|
f 73/154/138 71/189/138 55/155/138
|
||||||
|
f 73/154/139 78/148/139 74/191/139
|
||||||
|
f 73/154/140 80/156/140 81/192/140
|
||||||
|
f 71/193/141 76/194/141 77/195/141
|
||||||
|
f 71/193/142 73/196/142 75/197/142
|
||||||
|
f 79/198/143 80/199/143 62/188/143
|
||||||
|
f 79/198/144 78/165/144 68/200/144
|
||||||
|
f 79/198/145 82/201/145 81/202/145
|
||||||
|
f 79/198/146 46/166/146 78/165/146
|
||||||
|
f 46/166/147 79/198/147 62/188/147
|
||||||
|
f 68/190/148 73/154/148 82/203/148
|
||||||
|
f 79/198/149 68/200/149 82/201/149
|
||||||
|
f 72/137/150 56/172/150 57/204/150
|
||||||
|
f 57/204/151 55/155/151 72/137/151
|
||||||
|
f 87/4/152 56/172/152 72/137/152
|
||||||
|
f 85/205/99 83/206/99 49/207/99
|
||||||
|
f 86/208/153 88/104/153 49/207/153
|
||||||
|
f 102/105/97 88/107/97 84/209/97
|
||||||
|
f 101/108/154 85/205/154 51/210/154
|
||||||
|
f 70/127/155 83/131/155 50/129/155
|
||||||
|
f 83/131/156 70/127/156 86/126/156
|
||||||
|
f 84/128/97 100/10/97 102/110/97
|
||||||
|
f 100/10/157 70/127/157 89/11/157
|
||||||
|
f 89/11/158 70/127/158 50/129/158
|
||||||
|
f 101/108/159 51/210/159 90/111/159
|
||||||
|
f 86/208/153 49/207/153 83/206/153
|
||||||
|
f 88/104/96 86/208/96 84/209/96
|
||||||
|
f 85/205/99 49/207/99 51/211/99
|
||||||
|
f 79/198/160 81/202/160 80/199/160
|
||||||
|
f 71/193/141 75/197/141 76/194/141
|
||||||
|
f 71/193/161 77/195/161 58/212/161
|
||||||
|
f 73/154/162 81/192/162 82/203/162
|
||||||
|
f 74/182/163 75/186/163 73/213/163
|
||||||
|
f 74/182/130 77/184/130 76/185/130
|
||||||
|
f 46/180/164 60/153/164 64/214/164
|
||||||
|
f 97/65/165 69/176/165 56/172/165
|
||||||
|
f 98/63/166 69/171/166 99/116/166
|
||||||
|
f 64/161/167 67/163/167 66/179/167
|
||||||
|
f 63/159/168 56/160/168 61/215/168
|
||||||
|
f 55/157/169 63/159/169 62/216/169
|
||||||
|
f 60/153/170 45/150/170 64/214/170
|
||||||
|
f 58/136/171 67/147/171 45/145/171
|
||||||
|
f 59/143/172 96/35/172 95/119/172
|
||||||
|
f 59/141/173 47/142/173 44/217/173
|
||||||
|
f 47/140/174 93/25/174 52/139/174
|
||||||
|
f 54/138/175 93/25/175 94/28/175
|
||||||
|
f 58/136/176 72/137/176 71/189/176
|
||||||
|
f 90/18/177 53/134/177 91/21/177
|
||||||
|
f 52/132/178 53/134/178 51/135/178
|
||||||
|
f 49/125/179 52/132/179 51/135/179
|
||||||
|
f 89/11/180 85/130/180 101/121/180
|
||||||
|
f 47/123/181 88/5/181 48/124/181
|
||||||
|
f 44/122/182 48/124/182 45/145/182
|
||||||
97
main.cpp
97
main.cpp
@@ -14,6 +14,7 @@ OK Fix the gaps between triangles (it also improved look of triangle edges)
|
|||||||
* Depth buffer
|
* Depth buffer
|
||||||
* FPS Camera
|
* FPS Camera
|
||||||
* Reading OBJ files
|
* Reading OBJ files
|
||||||
|
* Loading a model from PMX?
|
||||||
* Rendering multiple objects, queue renderer
|
* Rendering multiple objects, queue renderer
|
||||||
* Clipping
|
* Clipping
|
||||||
* Optimizations
|
* Optimizations
|
||||||
@@ -22,14 +23,24 @@ OK Fix the gaps between triangles (it also improved look of triangle edges)
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* What a codebase needs:
|
||||||
|
* Macros for debug, release, slow, fast builds, where debug - tooling, slow - enable asserts
|
||||||
|
* Macros for OS, Compiler, Architecture
|
||||||
|
* Nice way of outputing visible error messages
|
||||||
|
* FatalError and Assert function for release builds with an error message, Debug Assert with error message for slow builds
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define OS_WINDOWS 1
|
||||||
#define BILINEAR_BLEND 1
|
#define BILINEAR_BLEND 1
|
||||||
#define PERSPECTIVE_CORRECT_INTERPOLATION 1
|
#define PERSPECTIVE_CORRECT_INTERPOLATION 1
|
||||||
#define DRAW_WIREFRAME 1
|
#define DRAW_WIREFRAME 1
|
||||||
|
#define DRAW_RECTS 0
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
#include "stb_image.h"
|
#include "stb_image.h"
|
||||||
|
#include "objparser.h"
|
||||||
|
|
||||||
struct Face {
|
struct Face {
|
||||||
int p[3];
|
int p[3];
|
||||||
@@ -71,15 +82,15 @@ void DrawRect(Image* dst, float X, float Y, float w, float h, U32 color) {
|
|||||||
|
|
||||||
for (int y = min_y; y < max_y; y++) {
|
for (int y = min_y; y < max_y; y++) {
|
||||||
for (int x = min_x; x < max_x; x++) {
|
for (int x = min_x; x < max_x; x++) {
|
||||||
dst->pixels[x + (dst->y - 1 - y) * dst->x] = color;
|
dst->pixels[x + y * dst->x] = color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FUNCTION
|
FUNCTION
|
||||||
void DrawBitmap(Image* dst, Image* src, Vec2 pos) {
|
void DrawBitmap(Image* dst, Image* src, Vec2 pos) {
|
||||||
I64 minx = (I64)(pos.x + 0.5f);
|
I64 minx = (I64)(pos.x + 0.5);
|
||||||
I64 miny = (I64)(pos.y + 0.5f);
|
I64 miny = (I64)(pos.y + 0.5);
|
||||||
I64 maxx = minx + src->x;
|
I64 maxx = minx + src->x;
|
||||||
I64 maxy = miny + src->y;
|
I64 maxy = miny + src->y;
|
||||||
I64 offsetx = 0;
|
I64 offsetx = 0;
|
||||||
@@ -105,7 +116,7 @@ void DrawBitmap(Image* dst, Image* src, Vec2 pos) {
|
|||||||
for (I64 x = minx; x < maxx; x++) {
|
for (I64 x = minx; x < maxx; x++) {
|
||||||
I64 tx = x - minx + offsetx;
|
I64 tx = x - minx + offsetx;
|
||||||
I64 ty = y - miny + offsety;
|
I64 ty = y - miny + offsety;
|
||||||
dst->pixels[x + (dst->y - 1 - y) * dst->x] = src->pixels[tx + (src->y - 1 - ty) * src->x];
|
dst->pixels[x + y * dst->x] = src->pixels[tx + ty * src->x];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -127,8 +138,6 @@ void DrawTriangle(Image* dst, Image *src, Vec4 p0, Vec4 p1, Vec4 p2,
|
|||||||
I64 min_y = (I64)MAX(0, Floor(min_y1));
|
I64 min_y = (I64)MAX(0, Floor(min_y1));
|
||||||
I64 max_x = (I64)MIN(dst->x, Ceil(max_x1));
|
I64 max_x = (I64)MIN(dst->x, Ceil(max_x1));
|
||||||
I64 max_y = (I64)MIN(dst->y, Ceil(max_y1));
|
I64 max_y = (I64)MIN(dst->y, Ceil(max_y1));
|
||||||
//@Todo: Fix the proper rounding
|
|
||||||
//@Todo: Determine whether we need subprecision etc
|
|
||||||
|
|
||||||
float area = EdgeFunction(p0, p1, p2);
|
float area = EdgeFunction(p0, p1, p2);
|
||||||
for (I64 y = min_y; y < max_y; y++) {
|
for (I64 y = min_y; y < max_y; y++) {
|
||||||
@@ -158,6 +167,7 @@ void DrawTriangle(Image* dst, Image *src, Vec4 p0, Vec4 p1, Vec4 p2,
|
|||||||
I64 vi = (I64)(v);
|
I64 vi = (I64)(v);
|
||||||
float udiff = u - (float)ui;
|
float udiff = u - (float)ui;
|
||||||
float vdiff = v - (float)vi;
|
float vdiff = v - (float)vi;
|
||||||
|
// Origin UV (0,0) is in bottom left
|
||||||
U32 *pixel = src->pixels + (ui + (src->y - 1ll - vi) * src->x);
|
U32 *pixel = src->pixels + (ui + (src->y - 1ll - vi) * src->x);
|
||||||
#if BILINEAR_BLEND
|
#if BILINEAR_BLEND
|
||||||
Vec4 pixelx1y1 = V4ABGR(*pixel);
|
Vec4 pixelx1y1 = V4ABGR(*pixel);
|
||||||
@@ -173,13 +183,15 @@ void DrawTriangle(Image* dst, Image *src, Vec4 p0, Vec4 p1, Vec4 p2,
|
|||||||
U32 color32 = *pixel;
|
U32 color32 = *pixel;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
dst->pixels[x + (dst->y - 1 - y) * dst->x] = color32;
|
dst->pixels[x + y * dst->x] = color32;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if DRAW_RECTS
|
||||||
DrawRect(dst, p0.x-4, p0.y-4, 8,8, 0x00ff0000);
|
DrawRect(dst, p0.x-4, p0.y-4, 8,8, 0x00ff0000);
|
||||||
DrawRect(dst, p1.x-4, p1.y-4, 8,8, 0x0000ff00);
|
DrawRect(dst, p1.x-4, p1.y-4, 8,8, 0x0000ff00);
|
||||||
DrawRect(dst, p2.x-4, p2.y-4, 8,8, 0x000000ff);
|
DrawRect(dst, p2.x-4, p2.y-4, 8,8, 0x000000ff);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
FUNCTION
|
FUNCTION
|
||||||
@@ -194,20 +206,50 @@ void DrawLine(Image *dst, float x0, float y0, float x1, float y1) {
|
|||||||
for (int i = 0; i <= longest_side_length; i++) {
|
for (int i = 0; i <= longest_side_length; i++) {
|
||||||
int x = (int)(current_x + 0.5f);
|
int x = (int)(current_x + 0.5f);
|
||||||
int y = (int)(current_y + 0.5f);
|
int y = (int)(current_y + 0.5f);
|
||||||
dst->pixels[x + (dst->y - 1 - y) * dst->x] = 0xffffffff;
|
dst->pixels[x + y * dst->x] = 0xffffffff;
|
||||||
current_x += x_inc;
|
current_x += x_inc;
|
||||||
current_y += y_inc;
|
current_y += y_inc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct FaceA {
|
||||||
|
int vertex[3];
|
||||||
|
int tex[3];
|
||||||
|
int normal[3];
|
||||||
|
};
|
||||||
|
|
||||||
|
FUNCTION
|
||||||
|
Obj LoadObj(const char* file) {
|
||||||
|
char* data = OS_ReadFile(file);
|
||||||
|
char* memory = (char*)malloc(100000);
|
||||||
|
Obj result = Obj_Parse(memory, 100000, data);
|
||||||
|
free(data);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
FUNCTION
|
||||||
|
Image LoadImage(const char* path) {
|
||||||
|
int x, y, n;
|
||||||
|
unsigned char* data = stbi_load(path, &x, &y, &n, 4);
|
||||||
|
Image result = { (U32*)data, x, y };
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
Obj_Test();
|
||||||
OS_Init({ 1280,720 });
|
OS_Init({ 1280,720 });
|
||||||
float rotation = 0;
|
float rotation = 0;
|
||||||
Vec3 camera_pos = {0,0,-5};
|
Vec3 camera_pos = {0,0,-5};
|
||||||
int x,y,n;
|
|
||||||
unsigned char *data = stbi_load("assets/bricksx64.png", &x, &y, &n, 4);
|
Obj obj = LoadObj("assets/f22.obj");
|
||||||
Image img = {(U32 *)data, x, y};
|
Vec3* vertices = (Vec3 *)obj.vertices;
|
||||||
Image screen320 = {(U32 *)malloc(320*180*sizeof(U32)), 140, 140};
|
Vec2* tex_coords = (Vec2*)obj.texture;
|
||||||
|
FaceA* faces = (FaceA*)obj.indices;
|
||||||
|
I64 face_count = obj.indices_count;
|
||||||
|
|
||||||
|
|
||||||
|
Image img = LoadImage("assets/bricksx64.png");
|
||||||
|
Image screen320 = {(U32 *)malloc(320*180*sizeof(U32)), 320, 180};
|
||||||
while (OS_GameLoop()) {
|
while (OS_GameLoop()) {
|
||||||
Mat4 perspective = Mat4Perspective(60.f, (float)screen.x, (float)screen.y, 0.1f, 100.f);
|
Mat4 perspective = Mat4Perspective(60.f, (float)screen.x, (float)screen.y, 0.1f, 100.f);
|
||||||
for (int y = 0; y < screen320.y; y++) {
|
for (int y = 0; y < screen320.y; y++) {
|
||||||
@@ -215,21 +257,22 @@ int main() {
|
|||||||
screen320.pixels[x + y * screen320.x] = 0;
|
screen320.pixels[x + y * screen320.x] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if 0
|
DrawBitmap(&screen320, &img, {0,0});
|
||||||
DrawTriangle(&screen320, &img, { 100,100 }, { 100,400 }, { 400,400 }, { 0,0 }, { 0,1 }, { 1,1 });
|
|
||||||
DrawTriangle(&screen320, &img, { 100,100 }, { 400,400 }, { 400,100}, { 0,0 }, { 1,1 }, { 1,0 });
|
|
||||||
#else
|
|
||||||
//DrawBitmap(&screen320, &img, {0,0});
|
|
||||||
Mat4 transform = Mat4RotationZ(rotation);
|
Mat4 transform = Mat4RotationZ(rotation);
|
||||||
transform = transform * Mat4RotationX(rotation);
|
transform = transform * Mat4RotationX(rotation);
|
||||||
if (keydown_a) rotation += 0.05f;
|
if (keydown_a) rotation += 0.05f;
|
||||||
if (keydown_b) rotation -= 0.05f;
|
if (keydown_b) rotation -= 0.05f;
|
||||||
for (int i = 0; i < ARRAY_CAP(cube_faces); i++) {
|
for (int i = 0; i < face_count; i++) {
|
||||||
Face* face = cube_faces + i;
|
FaceA* face = faces + i;
|
||||||
Vec4 pos[3] = {
|
Vec4 pos[3] = {
|
||||||
vec4(cube_vertices[face->p[0] - 1], 1),
|
vec4(vertices[face->vertex[0] - 1], 1),
|
||||||
vec4(cube_vertices[face->p[1] - 1], 1),
|
vec4(vertices[face->vertex[1] - 1], 1),
|
||||||
vec4(cube_vertices[face->p[2] - 1], 1),
|
vec4(vertices[face->vertex[2] - 1], 1),
|
||||||
|
};
|
||||||
|
Vec2 tex[3] = {
|
||||||
|
tex_coords[face->tex[0] - 1],
|
||||||
|
tex_coords[face->tex[1] - 1],
|
||||||
|
tex_coords[face->tex[2] - 1],
|
||||||
};
|
};
|
||||||
|
|
||||||
//@Note: Transform
|
//@Note: Transform
|
||||||
@@ -256,7 +299,8 @@ int main() {
|
|||||||
pos[j].x += screen320.x / 2;
|
pos[j].x += screen320.x / 2;
|
||||||
pos[j].y += screen320.y / 2;
|
pos[j].y += screen320.y / 2;
|
||||||
}
|
}
|
||||||
DrawTriangle(&screen320, &img, pos[0], pos[1], pos[2], face->tex[0], face->tex[1], face->tex[2]);
|
|
||||||
|
DrawTriangle(&screen320, &img, pos[0], pos[1], pos[2], tex[0], tex[1], tex[2]);
|
||||||
#if DRAW_WIREFRAME
|
#if DRAW_WIREFRAME
|
||||||
DrawLine(&screen320, pos[0].x, pos[0].y, pos[1].x, pos[1].y);
|
DrawLine(&screen320, pos[0].x, pos[0].y, pos[1].x, pos[1].y);
|
||||||
DrawLine(&screen320, pos[1].x, pos[1].y, pos[2].x, pos[2].y);
|
DrawLine(&screen320, pos[1].x, pos[1].y, pos[2].x, pos[2].y);
|
||||||
@@ -265,6 +309,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Note: Draw 320screen to OS screen
|
||||||
U32* ptr = screen.pixels;
|
U32* ptr = screen.pixels;
|
||||||
for (int y = 0; y < screen.y; y++) {
|
for (int y = 0; y < screen.y; y++) {
|
||||||
for (int x = 0; x < screen.x; x++) {
|
for (int x = 0; x < screen.x; x++) {
|
||||||
@@ -272,12 +317,8 @@ int main() {
|
|||||||
float v = (float)y / (float)screen.y;
|
float v = (float)y / (float)screen.y;
|
||||||
int tx = (int)(u * screen320.x + 0.5f);
|
int tx = (int)(u * screen320.x + 0.5f);
|
||||||
int ty = (int)(v * screen320.y + 0.5f);
|
int ty = (int)(v * screen320.y + 0.5f);
|
||||||
U32 pixel = screen320.pixels[tx + ty * (screen320.x)];
|
*ptr++ = screen320.pixels[tx + ty * (screen320.x)];
|
||||||
// 0xABGR to 0xARGB
|
|
||||||
// b > 24 g > 8 r < 8
|
|
||||||
*ptr++ = ((pixel & 0xff000000)) | ((pixel & 0x00ff0000) >> 16) | ((pixel & 0x0000ff00)) | ((pixel & 0x000000ff) << 16);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
240
objparser.cpp
Normal file
240
objparser.cpp
Normal file
@@ -0,0 +1,240 @@
|
|||||||
|
#include "objparser.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
enum class TokenType {
|
||||||
|
none, word, number, whitespace, end
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Token {
|
||||||
|
TokenType type;
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
|
char* s;
|
||||||
|
int len;
|
||||||
|
};
|
||||||
|
double number;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
static
|
||||||
|
bool Obj_IsAlphabetic(char w) {
|
||||||
|
bool result = (w >= 'a' && w <= 'z') || (w >= 'A' && w <= 'Z');
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
bool Obj_IsNumber(char w) {
|
||||||
|
bool result = w >= '0' && w <= '9';
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
bool Obj_IsWhitespace(char w) {
|
||||||
|
bool result = w == '\n' || w == ' ' || w == '\t' || w == '\v' || w == '\r';
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
int Obj_StringLen(char* a) {
|
||||||
|
int result = 0;
|
||||||
|
while (*a++ != 0) result++;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
bool Obj_Equals(Token a, const char* b) {
|
||||||
|
int len = Obj_StringLen((char*)b);
|
||||||
|
if (a.type != TokenType::word) return false;
|
||||||
|
if (a.len != len) return false;
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
if (a.s[i] != b[i]) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
Token Obj_NextTokenRaw(char** data) {
|
||||||
|
Token result = {};
|
||||||
|
result.s = *data;
|
||||||
|
*data += 1;
|
||||||
|
|
||||||
|
if (Obj_IsAlphabetic(*result.s)) {
|
||||||
|
result.type = TokenType::word;
|
||||||
|
while (!Obj_IsWhitespace(**data)) {
|
||||||
|
*data+=1;
|
||||||
|
}
|
||||||
|
result.len = (int)(*data - result.s);
|
||||||
|
}
|
||||||
|
else if (Obj_IsNumber(*result.s) || *result.s == '-') {
|
||||||
|
result.type = TokenType::number;
|
||||||
|
while (Obj_IsNumber(**data) || **data == '.') {
|
||||||
|
*data += 1;
|
||||||
|
}
|
||||||
|
result.number = atof(result.s);
|
||||||
|
}
|
||||||
|
else if (*result.s == '#') {
|
||||||
|
while (**data != '\n') *data += 1;
|
||||||
|
result = Obj_NextTokenRaw(data);
|
||||||
|
}
|
||||||
|
else if (Obj_IsWhitespace(*result.s)) {
|
||||||
|
result.type = TokenType::whitespace;
|
||||||
|
while (Obj_IsWhitespace(**data)) *data += 1;
|
||||||
|
result.len = (int)(*data - result.s);
|
||||||
|
}
|
||||||
|
else if (*result.s == 0) {
|
||||||
|
result.type = TokenType::end;
|
||||||
|
}
|
||||||
|
else if(*result.s >= '!') {
|
||||||
|
result.type = (TokenType)*result.s;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
Token Obj_NextToken(char** data) {
|
||||||
|
Token result;
|
||||||
|
do {
|
||||||
|
result = Obj_NextTokenRaw(data);
|
||||||
|
} while (result.type == TokenType::whitespace);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
double Obj_ExpectNumber(char** data) {
|
||||||
|
Token t = Obj_NextToken(data);
|
||||||
|
assert(t.type == TokenType::number); // @Todo: Error handling, error flag
|
||||||
|
return t.number;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void Obj_ExpectToken(char** data, char token) {
|
||||||
|
Token t = Obj_NextToken(data);
|
||||||
|
assert(t.type == (TokenType)token); // @Todo: Error handling, error flag
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void Obj_Debug_ExpectRaw(char** data, TokenType type) {
|
||||||
|
char* data_temp = *data;
|
||||||
|
assert(Obj_NextTokenRaw(&data_temp).type == type);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Obj_Arena {
|
||||||
|
char* base;
|
||||||
|
size_t size;
|
||||||
|
size_t p;
|
||||||
|
};
|
||||||
|
|
||||||
|
static
|
||||||
|
char* Obj_Push(Obj_Arena *a, size_t size) {
|
||||||
|
char* ptr = a->base;
|
||||||
|
if (a->p + size < a->size) {
|
||||||
|
ptr += a->p;
|
||||||
|
a->p += size;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
assert(!"Buffer is too small to hold the data!");
|
||||||
|
}
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Obj Obj_Parse(char* memory, size_t memory_size, char* data) {
|
||||||
|
Obj_Arena arena = { memory, memory_size };
|
||||||
|
Obj result = {};
|
||||||
|
int parsing_vertices = 0;
|
||||||
|
int parsing_normals = 0;
|
||||||
|
int parsing_textures = 0;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
Token token = Obj_NextToken(&data);
|
||||||
|
if (token.type == TokenType::end) break;
|
||||||
|
else if (token.type == TokenType::word) {
|
||||||
|
if (Obj_Equals(token, "v")) {
|
||||||
|
assert(parsing_vertices != 2);
|
||||||
|
parsing_vertices = 1;
|
||||||
|
float* ptr = (float*)Obj_Push(&arena, sizeof(float) * 3);
|
||||||
|
ptr[0] = (float)Obj_ExpectNumber(&data);
|
||||||
|
ptr[1] = (float)Obj_ExpectNumber(&data);
|
||||||
|
ptr[2] = (float)Obj_ExpectNumber(&data);
|
||||||
|
if (result.vertices == 0) result.vertices = ptr;
|
||||||
|
result.vertices_count++;
|
||||||
|
Obj_Debug_ExpectRaw(&data, TokenType::whitespace);
|
||||||
|
}
|
||||||
|
else if (Obj_Equals(token, "vt")) {
|
||||||
|
assert(parsing_textures != 2);
|
||||||
|
parsing_textures = 1;
|
||||||
|
parsing_vertices = 2;
|
||||||
|
|
||||||
|
float* ptr = (float*)Obj_Push(&arena, sizeof(float) * 2);
|
||||||
|
ptr[0] = (float)Obj_ExpectNumber(&data);
|
||||||
|
ptr[1] = (float)Obj_ExpectNumber(&data);
|
||||||
|
if (result.texture == 0) result.texture = ptr;
|
||||||
|
Obj_Debug_ExpectRaw(&data, TokenType::whitespace);
|
||||||
|
}
|
||||||
|
else if (Obj_Equals(token, "vn")) {
|
||||||
|
assert((parsing_textures == 1 || parsing_textures == 2) && parsing_vertices == 2);
|
||||||
|
parsing_textures = 2;
|
||||||
|
parsing_normals = 1;
|
||||||
|
|
||||||
|
float* ptr = (float*)Obj_Push(&arena, sizeof(float) * 3);
|
||||||
|
ptr[0] = (float)Obj_ExpectNumber(&data);
|
||||||
|
ptr[1] = (float)Obj_ExpectNumber(&data);
|
||||||
|
ptr[2] = (float)Obj_ExpectNumber(&data);
|
||||||
|
if (result.normals == 0) result.normals = ptr;
|
||||||
|
Obj_Debug_ExpectRaw(&data, TokenType::whitespace);
|
||||||
|
}
|
||||||
|
else if (Obj_Equals(token, "f")) {
|
||||||
|
assert(parsing_normals == 1 && parsing_textures == 2 && parsing_vertices == 2);
|
||||||
|
int* ptr = (int*)Obj_Push(&arena, sizeof(int) * 9);
|
||||||
|
ptr[0] = (int)Obj_ExpectNumber(&data);
|
||||||
|
Obj_ExpectToken(&data, '/');
|
||||||
|
ptr[3] = (int)Obj_ExpectNumber(&data);
|
||||||
|
Obj_ExpectToken(&data, '/');
|
||||||
|
ptr[6] = (int)Obj_ExpectNumber(&data);
|
||||||
|
|
||||||
|
ptr[1] = (int)Obj_ExpectNumber(&data);
|
||||||
|
Obj_ExpectToken(&data, '/');
|
||||||
|
ptr[4] = (int)Obj_ExpectNumber(&data);
|
||||||
|
Obj_ExpectToken(&data, '/');
|
||||||
|
ptr[7] = (int)Obj_ExpectNumber(&data);
|
||||||
|
|
||||||
|
ptr[2] = (int)Obj_ExpectNumber(&data);
|
||||||
|
Obj_ExpectToken(&data, '/');
|
||||||
|
ptr[5] = (int)Obj_ExpectNumber(&data);
|
||||||
|
Obj_ExpectToken(&data, '/');
|
||||||
|
ptr[8] = (int)Obj_ExpectNumber(&data);
|
||||||
|
if (result.indices == 0) result.indices = ptr;
|
||||||
|
result.indices_count += 1;
|
||||||
|
|
||||||
|
Obj_Debug_ExpectRaw(&data, TokenType::whitespace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.memory_taken = arena.p;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void Obj_TestLex() {
|
||||||
|
const char* d = "v 0.885739 0.001910 -0.380334";
|
||||||
|
char* dd = (char *)d;
|
||||||
|
assert(Obj_NextToken(&dd).type == TokenType::word);
|
||||||
|
Token t = Obj_NextToken(&dd); assert(t.type == TokenType::number && t.number > 0.8857);
|
||||||
|
t = Obj_NextToken(&dd); assert(t.type == TokenType::number && t.number > 0.0019);
|
||||||
|
t = Obj_NextToken(&dd); assert(t.type == TokenType::number && t.number < -0.38);
|
||||||
|
d = "# Blender v2.79 (sub 0) OBJ File: 'fighters_0.blend'\n"
|
||||||
|
"# www.blender.org\n"
|
||||||
|
"mtllib f-22.mtl\n"
|
||||||
|
"o F-22\n";
|
||||||
|
dd = (char *)d;
|
||||||
|
t = Obj_NextToken(&dd); assert(t.type == TokenType::word && Obj_Equals(t, (char*)"mtllib"));
|
||||||
|
t = Obj_NextToken(&dd); assert(t.type == TokenType::word && Obj_Equals(t, (char*)"f-22.mtl"));
|
||||||
|
t = Obj_NextToken(&dd); assert(t.type == TokenType::word && Obj_Equals(t, (char*)"o"));
|
||||||
|
t = Obj_NextToken(&dd); assert(t.type == TokenType::word && Obj_Equals(t, (char*)"F-22"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Obj_Test() {
|
||||||
|
Obj_TestLex();
|
||||||
|
}
|
||||||
14
objparser.h
Normal file
14
objparser.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
struct Obj {
|
||||||
|
float* vertices; // sets of 3 floats
|
||||||
|
float* texture; // sets of 2 floats
|
||||||
|
float* normals; // sets of 3 floats
|
||||||
|
int vertices_count; // count of sets(vertices, textures, normals)
|
||||||
|
|
||||||
|
int* indices; // layout: vvv/ttt/nnn
|
||||||
|
int indices_count; // 1 count == 1 full face == 3vertex indices, 3 texture coordinate indices, 3 normal indices
|
||||||
|
size_t memory_taken;
|
||||||
|
};
|
||||||
|
|
||||||
|
Obj Obj_Parse(char* memory, size_t memory_size, char* data);
|
||||||
|
void Obj_Test();
|
||||||
61
platform.cpp
61
platform.cpp
@@ -1,7 +1,13 @@
|
|||||||
|
/*
|
||||||
|
* The OS layer should expect ABGR writes to the screen, the bitmap is bottom up(origin 0,0 is in left bottom corner)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <shellscalingapi.h>
|
#include <shellscalingapi.h>
|
||||||
|
|
||||||
|
|
||||||
typedef HRESULT tSetProcessDpiAwareness(PROCESS_DPI_AWARENESS);
|
typedef HRESULT tSetProcessDpiAwareness(PROCESS_DPI_AWARENESS);
|
||||||
|
|
||||||
Image screen;
|
Image screen;
|
||||||
@@ -49,7 +55,7 @@ void Win32_ScreenInit(int window_x, int window_y) {
|
|||||||
BITMAPINFO bminfo = {};
|
BITMAPINFO bminfo = {};
|
||||||
bminfo.bmiHeader.biSize = sizeof(bminfo.bmiHeader);
|
bminfo.bmiHeader.biSize = sizeof(bminfo.bmiHeader);
|
||||||
bminfo.bmiHeader.biWidth = window_x;
|
bminfo.bmiHeader.biWidth = window_x;
|
||||||
bminfo.bmiHeader.biHeight = -window_y;
|
bminfo.bmiHeader.biHeight = window_y;
|
||||||
bminfo.bmiHeader.biPlanes = 1;
|
bminfo.bmiHeader.biPlanes = 1;
|
||||||
bminfo.bmiHeader.biBitCount = 32;
|
bminfo.bmiHeader.biBitCount = 32;
|
||||||
bminfo.bmiHeader.biCompression = BI_RGB; // AA RR GG BB
|
bminfo.bmiHeader.biCompression = BI_RGB; // AA RR GG BB
|
||||||
@@ -134,10 +140,21 @@ bool OS_GameLoop() {
|
|||||||
Win32_ScreenInit((LONG)screen.x, (LONG)screen.y);
|
Win32_ScreenInit((LONG)screen.x, (LONG)screen.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Note: Draw screen to window
|
||||||
|
U32* p = screen.pixels;
|
||||||
|
if (p != 0) {
|
||||||
|
// @Note: Convert 0xABGR to 0xARGB
|
||||||
|
for (int y = 0; y < screen.y; y++) {
|
||||||
|
for (int x = 0; x < screen.x; x++) {
|
||||||
|
*p = ((*p & 0xff000000)) | ((*p & 0x00ff0000) >> 16) | ((*p & 0x0000ff00)) | ((*p & 0x000000ff) << 16);
|
||||||
|
p += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// @Note; Draw screen to window
|
SelectObject(g_screen_dc, g_screen_dib);
|
||||||
SelectObject(g_screen_dc, g_screen_dib);
|
BitBlt(g_window_dc, 0, 0, (int)screen.x, (int)screen.y, g_screen_dc, 0, 0, SRCCOPY);
|
||||||
BitBlt(g_window_dc, 0, 0, (int)screen.x, (int)screen.y, g_screen_dc, 0, 0, SRCCOPY);
|
}
|
||||||
|
|
||||||
Sleep(16);
|
Sleep(16);
|
||||||
return g_app_is_running;
|
return g_app_is_running;
|
||||||
}
|
}
|
||||||
@@ -147,4 +164,40 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
|
|||||||
g_hinstance = hInstance;
|
g_hinstance = hInstance;
|
||||||
g_cmdshow = nCmdShow;
|
g_cmdshow = nCmdShow;
|
||||||
return main();
|
return main();
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
void OS_Message(const char* format, ...) {
|
||||||
|
char buffer[1024];
|
||||||
|
va_list args;
|
||||||
|
va_start(args, format);
|
||||||
|
vsnprintf(buffer, 1024, format, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
MessageBoxA(0, buffer, "Error!", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
char* OS_ReadFile(const char* path) {
|
||||||
|
char* result = 0;
|
||||||
|
FILE* f = fopen(path, "rb");
|
||||||
|
if (f) {
|
||||||
|
fseek(f, 0, SEEK_END);
|
||||||
|
U64 fsize = ftell(f);
|
||||||
|
fseek(f, 0, SEEK_SET);
|
||||||
|
|
||||||
|
result = (char*)malloc(fsize + 1ll);
|
||||||
|
if (result) {
|
||||||
|
fread(result, fsize, 1, f);
|
||||||
|
result[fsize] = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ASSERT(!"Malloc failed!")
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ASSERT(!"Failed to read file");
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
@@ -17,4 +17,5 @@ extern bool keydown_a;
|
|||||||
extern bool keydown_b;
|
extern bool keydown_b;
|
||||||
|
|
||||||
bool OS_GameLoop();
|
bool OS_GameLoop();
|
||||||
void OS_Init(OSInitArgs);
|
void OS_Init(OSInitArgs);
|
||||||
|
char* OS_ReadFile(const char* path);
|
||||||
Reference in New Issue
Block a user