-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbase_graphics.c
More file actions
104 lines (81 loc) · 2.23 KB
/
base_graphics.c
File metadata and controls
104 lines (81 loc) · 2.23 KB
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
#include <stdio.h> /* printf */
#include <stdlib.h> /* malloc free */
#include <stddef.h> /* size_t */
#include <string.h> /* memset */
#include <GLUT/glut.h>
#include "point.h"
#include "input.h"
#include "frame_cache.h"
#include "undo.h"
/* Though the OpenGL APIs used in this program is abandoned and outdated, I have
* to use it still because I don't have plenty of time to improve my coursework and
* use new version APIs.
*/
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
extern bg_frame
current;
/* private functions */
static void
__flush() {
glClear(GL_COLOR_BUFFER_BIT);
struct bg_point p; /* p is temporary variable */
glColor3f(0.0f, 0.0f, 0.0f);
glBegin(GL_POINTS);
for (p.x=0; p.x<400; ++p.x) {
for (p.y=0; p.y<400; ++p.y) {
if (0 != current[p.x][p.y]) {
glVertex2i(p.x, p.y);
}
}
}
glEnd();
glutSwapBuffers();
return;
}
/* public functions */
/* Initializing.
*
* It must be called before using the library. */
void
bg_init() {
/* simplified initialization */
int fake_argc=1;
char * fake_arg="";
char ** fake_argv=&fake_arg;
glutInit(&fake_argc, fake_argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(400, 400);
glutCreateWindow("Computer graphics coursework");
/* TODO may could be removed */
glutDisplayFunc(__flush);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0, 400, 0, 400);
/* initialize menu */
glutCreateMenu(bg_menu_callback);
glutAttachMenu(GLUT_RIGHT_BUTTON);
/* initialize mouse */
glutMouseFunc(bg_mouse_plot_callback);
glutPassiveMotionFunc(bg_mouse_move_callback);
glutMotionFunc(bg_mouse_drag_callback);
/* initialize keyboard */
glutKeyboardFunc(bg_keyboard_callback);
/* initialize undo stack
*
* Committing a complete white screen when initializing in case of wrong
* display at the first operation. If not, overlapping pattern appears.
*/
bg_undo_commit();
return;
}
void bg_clean() {
memset(current, 0, sizeof(current));
bg_undo_commit();
return;
}
void
bg_mainloop()
{
glutMainLoop();
return;
}