Repository navigation
Expand file tree
/
Copy pathMain.cpp
More file actions
200 lines (144 loc) · 5.27 KB
/
Copy pathMain.cpp
File metadata and controls
200 lines (144 loc) · 5.27 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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>
#include <iostream>
#include "Image.h"
#include "ImageStack.h"
#include "ApplicationWindow.h"
#define MSEC_FRAMES 17/* 60 FPS(~17 milliseconds between frames) is enough, '0' will disable frame limiter */
unsigned const int imageWidth = 512, imageHeight = 512;
void gl_init(){
glClearColor (0.0, 0.0, 0.0, 0.0);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
GLubyte image[imageWidth][imageHeight][3];
Image img, maskimage;
/** Here comes my image creation process **/
Image_ptr base_ptr = Image_ptr(new Image(
Image::createCheckersBoard(imageWidth,imageHeight,Color::RED,Color::YELLOW,64,64)
));
Image_ptr layer1 = Image_ptr(new Image(
Image::createCheckersBoard(imageWidth,imageHeight,Color::BLACK,Color::WHITE,128,128)
));
Image_ptr layer2 = Image_ptr(new Image(
//Image::createCheckersBoard(2*imageWidth,2*imageHeight,Color::BLACK,Color::WHITE,8,8)
//Image::createRandomBicolorNoise(2*imageWidth,2*imageHeight)
Image::createPerlinNoise(2*imageWidth,2*imageHeight,
Color::BLACK,Color::WHITE,1./10 /*scale*/,0./*time*/)
));
layer2->rotate(Image::PI/8);
std::vector<std::vector<float> > mask1 = Image::createSolidColorMask(imageWidth,imageHeight,.5);
ImageStack stack( base_ptr );
stack.push(layer1, mask1);
stack.push(layer2,Image::createSolidColorMask(2*imageWidth,2*imageHeight,0.2));
//add to stack
img = stack.getCondensedImage();
/** Here it ends and i copy it to an array **/
for(unsigned int i = 0; i<imageWidth;++i)
for(unsigned int j = 0; j<imageHeight;++j){
image[i][j][0] = img.at(i,j).getRed();
image[i][j][1] = img.at(i,j).getGreen();
image[i][j][2] = img.at(i,j).getBlue();
}
// loadImage();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, 3, imageWidth,
imageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,
&image[0][0][0]);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_FLAT);
}
bool pollEvents()
{
SDL_Event event;
while( SDL_PollEvent(&event) )
{
switch(event.type)
{
case SDL_QUIT:
return false;
default:
break;
}
}
return true;
}
int main(int argc, char **argv)
{
if( SDL_Init( SDL_INIT_VIDEO ) != 0 ) // Initialisieren des SDL Video Subsystems
{
std::cout << "Die SDL konnte nicht initalisiert werden (" << SDL_GetError() << ")" << std::endl;
return 1;
}
ApplicationWindow *game_window =
new ApplicationWindow( 800, 600, 32 );
game_window->setCaption( "64k Intro Test-01" );
game_window->create();
// Die Endlosschleife
unsigned int counter = 0;
unsigned int tlast = 0, tcurrent, st;
st = SDL_GetTicks();
gl_init();
while(true)
{
//-------------------------
// Nachrichten verarbeiten:
//-------------------------
if( !pollEvents() ) break;
tcurrent = SDL_GetTicks();
if(tcurrent < tlast + MSEC_FRAMES)
usleep(1000*(tlast + MSEC_FRAMES - tcurrent));
counter++;
counter = counter%360;
//----------------------------------
// Den aktuellen Bildbuffer löschen:
//----------------------------------
glClearColor( 0.0, 0.0, 0.1, 0.0 ); // Farbe zum Löschen setzen
glClear( GL_COLOR_BUFFER_BIT ); // Aktuellen Bildbuffer löschen
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
//--------------------------
// Die Projektion festlegen:
//--------------------------
glMatrixMode( GL_PROJECTION ); // Stack für Projektionsmatrix als
// aktiven Matrixstack setzen
glLoadIdentity(); // Identitätsmatrix auf den Stack laden
// Eine orthogonale Projektionsmatrix zum Stack
// dazu multiplizieren.
glOrtho( 0, 800, 600, 0, -1, 1 );
//gluPerspective(60, 800./600, 0, 4);
//gluLookAt(px,py,pz, lx,ly,lz, ux,uy,uz);
//gluLookAt(1,1,1, 0,0,0, 0,1,0);
//----------------------
// Texturen malen
//----------------------
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
//shift to center of the quad and rotate
glTranslated(200,300,0);
glRotated(counter/1.,0,0,1);
glTranslated(-200,-300,0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin( GL_QUADS );
glTexCoord2f(0.0f, 0.0f); glVertex3f(100,200,0);
glTexCoord2f(0.0f, 1.0f); glVertex3f(100,400,0);
glTexCoord2f(1.0f, 1.0f); glVertex3f(300,400,0);
glTexCoord2f(1.0f, 0.0f); glVertex3f(300,200,0);
glEnd();
//draw an unrotated quad
glLoadIdentity();
glBegin( GL_QUADS );
glTexCoord2f(0.0f, 0.0f); glVertex3f(100+400,200,0);
glTexCoord2f(0.0f, 1.0f); glVertex3f(100+400,400,0);
glTexCoord2f(1.0f, 1.0f); glVertex3f(300+400,400,0);
glTexCoord2f(1.0f, 0.0f); glVertex3f(300+400,200,0);
glEnd();
SDL_GL_SwapBuffers(); // Bildbuffer vertauschen (als Letztes)
tlast = tcurrent;
}
SDL_Quit();
return 0;
}