-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDirectoOpenGL_Draw_test.cpp
160 lines (126 loc) · 3.1 KB
/
DirectoOpenGL_Draw_test.cpp
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <gl/freeglut.h>
#include <cmath>
#include <iostream>
struct Color
{
float r;
float g;
float b;
};
bool spr = true;
float spd = 0.5f;
struct Player
{
Player()
{
//sprite = new Color[30];
Color tmp;
tmp.r = 1.0f;
tmp.g = 0.8f;
tmp.b = 0.5f;
for(int i = 0; i < 30; ++i)
{
sprite[i] = tmp;
}
Color black;
black.r = 0.0f;
black.g = 0.0f;
black.b = 0.0f;
sprite[2] = black, sprite[3] = black, sprite[4] = black;
sprite[2+5] = black, sprite[3+5] = black, sprite[4+5] = black;
sprite[2+5*2] = black, sprite[3+5*2] = black, sprite[4+5*2] = black;
sprite[3+5*3] = black;
sprite[3+5*4] = black;
sprite[1+5*5] = sprite[2+5*5] = sprite[3+5*5] = sprite[4+5*5] = black;
x = 10.f, y = 12.f;
}
void Render(Color* buf)
{
int ix = x;
int iy = y;
Color black;
black.r = 0.0f;
black.g = 0.0f;
black.b = 0.0f;
for(int i = 0; i < 6; ++i)
{
for(int j = 0; j < 5; ++j)
{
buf[500*(iy+i) + ix + j] = spr ? sprite[5*i + j] : black; //LOL
}
}
}
Color sprite[30];
float x, y;
};
Color* myBuffer;
Player pl;
Color* buildBuffer()
{
Color* buff = new Color[500*500];
Color tmp;
tmp.r = 1.0f;
tmp.g = 0.8f;
tmp.b = 0.5f;
for(int i = 0; i < 500*500; ++i)
{
buff[i] = tmp;
}
return buff;
}
void clearMyBuffer()
{
Color tmp;
tmp.r = 1.0f;
tmp.g = 0.8f;
tmp.b = 0.5f;
for(int i = 0; i < 500*500; ++i)
{
myBuffer[i] = tmp;
}
}
void renderWorld()
{
//glClear(GL_COLOR_BUFFER_BIT); //I DONT HEED THIS HAHAHAH!!! SUCK IT, OPENGL!!
//clearMyBuffer();
pl.Render(myBuffer);
glDrawPixels(500, 500, GL_RGB, GL_FLOAT, myBuffer);
glutSwapBuffers();
}
void asciiKeyPressed(unsigned char k, int x, int y)
{
switch(k)
{
case 'i': pl.y += spd; break;
case 'k': pl.y -= spd; break;
case 'j': pl.x -= spd; break;
case 'l': pl.x += spd; break;
case 's': spr ? spr = false : spr = true; break;
case 'w': spd += 0.3f; break;
}
}
int main(int argc, char *argv[])
{
myBuffer = buildBuffer();
// initialise GLUT + create Window
glutInit(&argc, argv);
glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB );
glutInitWindowPosition(400, 400);
glutInitWindowSize(500, 500);
glutCreateWindow("DirectDraw");
// register callbacks for winAPI
glutDisplayFunc(renderWorld);
glutIdleFunc(renderWorld); // render scene every frame even when idle
//glutIgnoreKeyRepeat(1); // ignore annoying windows key repeat delay
// user input callbacks
glutKeyboardFunc(asciiKeyPressed); // process "normal" keys
//glutSpecialFunc(specKeyPressed); // process "special" keys
//glutSpecialUpFunc(specKeyReleased); // check if "special" key is released
//glutMouseFunc(mouseButton); // register mouse buttons press
//glutMotionFunc(mouseMove); // register mouse movement with pressed button
// OpenGL initialisation
// enter glut event processing infinite loop
glutMainLoop();
delete[] myBuffer;
return 0;
}