-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
110 lines (93 loc) · 2.51 KB
/
main.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <stdlib.h>
#include <stdio.h>
#include "SDL.h"
#include "drawline.h"
#include "triangle.h"
#include "teapot_data.h"
triangle_t exampletriangle1 = {
.x1 = 100,
.y1 = 200,
.x2 = 200,
.y2 = 100,
.x3 = 300,
.y3 = 300,
.fillcolor = 0xffff0000,
.scale = 1.0
};
triangle_t exampletriangle2 = {
.x1 = 50,
.y1 = 150,
.x2 = 150,
.y2 = 50,
.x3 = 250,
.y3 = 250,
.fillcolor = 0xffffff00,
.scale = 1.0
};
triangle_t exampletriangle3 = {
.x1 = 350,
.y1 = 350,
.x2 = 460,
.y2 = 300,
.x3 = 500,
.y3 = 400,
.fillcolor = 0xff00ff00,
.scale = 1.0
};
triangle_t exampletriangle4 = {
.x1 = 350,
.y1 = 100,
.x2 = 450,
.y2 = 50,
.x3 = 500,
.y3 = 200,
.fillcolor = 0xff0000ff,
.scale = 1.0
};
// First function run in your program
int main(int argc, char **argv)
{
int retval, done;
SDL_Surface *screen;
SDL_Event event;
// Initialize SDL
retval = SDL_Init(SDL_INIT_VIDEO);
if (retval == -1) {
printf("Unable to initialize SDL\n");
exit(1);
}
//Create a 1024x768x32 window
screen = SDL_SetVideoMode(1024, 768, 32, 0);
if (screen == NULL) {
printf("Unable to get video surface: %s\n", SDL_GetError());
exit(1);
}
// The teapot is represented as an array of triangle data structures.
// To draw it on the screen you need to traverse the 'teapot_model' array
// and call DrawTriangle for each triangle (teapot_data.h contains the array).
// The definition TEAPOT_NUMTRIANGLES specifies the number of triangles in the array.
// The teapot model is contained within a 1000x1000 box (coordinates
// from -500 to 500 on the x and y axis). Remember to translate the
// model to the middle of the screen before drawing it (initialize
// triangle->tx and triangle->ty with the appropriate coordinates).
// Draw some example triangles on the screen.
// Use these examples in the beginning.
// Flush events
while(SDL_PollEvent(&event));
DrawTriangle(screen, &exampletriangle1);
DrawTriangle(screen, &exampletriangle2);
DrawTriangle(screen, &exampletriangle3);
DrawTriangle(screen, &exampletriangle4);
done = 0;
while (done == 0) {
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
done = 1;
break;
}
}
}
SDL_Quit();
return 0;
}