forked from theZiz/sparrow3d
/
testmesh.c
95 lines (81 loc) · 2.69 KB
/
testmesh.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
The contents of this file are subject to the "do whatever you like"-license.
That means: Do, whatver you want, this file is under public domain. It is an
example for sparrow3d. Copy it and learn from it for your project and release
it under every license you want. ;-)
For feedback and questions about my Files and Projects please mail me,
Alexander Matthes (Ziz) , zizsdl_at_googlemail.com
*/
#include "../sparrow3d/sparrow3d.h"
#include <SDL_image.h>
SDL_Surface* screen;
SDL_Surface* texture;
spModelPointer mesh;
Sint32 rotation = 0;
void draw_function(void)
{
//Reseting Z Buffer to the maximal negative value
spResetZBuffer();
//Cleaning the target (in this case the screen surface) with 0 (black).
spClearTarget(0);
//Reseting the ModelViewMatrix to an identity matrix.
spIdentity();
//Binding the texture
spBindTexture(texture);
//Going to the "position" -8.0f
spTranslate(0,0,-8<<SP_ACCURACY);
//rotation aorund every axis
spRotateX(rotation);
spRotateY(rotation);
spRotateZ(rotation);
spRotateX(SP_PI/8);
//Drawing the mesh and no update of the edgelist
spMesh3D(mesh,0);
//Show it!
spFlip();
}
int calc_function(Uint32 steps)
{
//update rotation counter
rotation+=steps*32;
//if "Start" (or "Menu" for Wiz or "Home" for Caanoo or "Return" at the P) is
//pressed: exit
if (spGetInput()->button[SP_BUTTON_START])
return 1;
return 0;
}
void resize(Uint16 w,Uint16 h)
{
//Setup of the new/resized window
spSetPerspective(50.0,(float)spGetWindowSurface()->w/(float)spGetWindowSurface()->h,0.1,100);
}
int main(int argc, char **argv)
{
//sparrow3D Init
spSetDefaultWindowSize(640,480); //Creates a 640x480 window at PC instead of 320x240
spInitCore();
//Setup
screen = spCreateDefaultWindow();
//Selecting the renderTarget. It could be every surface
spSelectRenderTarget(screen);
resize(screen->w,screen->h);
//Textures loading
texture = spLoadSurface("./data/garfield.png");
//Setting alpha test to 0, because the texture has pink parts
spSetAlphaTest(0);
//Mesh loading
mesh = spMeshLoadObj("./data/testmeshuv_tri.obj",texture,65535);
//Light on! There is one "default" light at 0,0,0 with color white. We just use it.
spSetLight(1);
//All glory the main loop
//every frame the draw_function is called
//every frame the calc_function is called with the past time as argument
//at least 10 ms have to be between to frames (max 100 fps)
//if the window is resized, the resize feedback-function is called (again)
spLoop(draw_function,calc_function,10,resize,NULL);
//Winter Wrap up, Winter Wrap up
spMeshDelete(mesh);
spDeleteSurface(texture);
spQuitCore();
return 0;
}