summaryrefslogtreecommitdiff
path: root/fractal.c
diff options
context:
space:
mode:
Diffstat (limited to 'fractal.c')
-rw-r--r--fractal.c125
1 files changed, 4 insertions, 121 deletions
diff --git a/fractal.c b/fractal.c
index 2f01a7f..783ad87 100644
--- a/fractal.c
+++ b/fractal.c
@@ -159,18 +159,6 @@ void generate_koh(int gener, double size, int posx, int posy, double k)
generate_koh(gener-1, t_size, posx+size-t_size/2, posy-t_size/2, k);
}
-void Rect( GLfloat w, GLfloat h )
-{
- /*
- glBegin( GL_QUADS );
- glVertex3f( -w, h, 0.0f );
- glVertex3f( w, h, 0.0f );
- glVertex3f( w, -h, 0.0f );
- glVertex3f( -w, -h, 0.0f );
- glEnd();
- */
-}
-
void Triangle( int x, int y, int w, int h)
{
// An array of 3 vectors which represents 3 vertices
@@ -206,7 +194,6 @@ void Triangle( int x, int y, int w, int h)
}
-
// Shader sources
const GLchar* vertexSource =
"attribute vec4 position; \n"
@@ -221,53 +208,17 @@ const GLchar* fragmentSource =
" gl_FragColor = vec4 (1.0, 1.0, 1.0, 1.0 );\n"
"} \n";
-
GLuint vertexShader;
GLuint fragmentShader;
GLuint shaderProgram;
GLint posAttrib;
-
void RectPX( int x, int y,int w, int h )
{
GLfloat x1 = (1.0f*x-SCREEN_WIDTH2)/SCREEN_WIDTH2;
GLfloat y1 = (1.0f*y-SCREEN_HEIGHT2)/SCREEN_HEIGHT2;
GLfloat x2 = (1.0f*(x+w)-SCREEN_WIDTH2)/SCREEN_WIDTH2;
GLfloat y2 = (1.0f*(y+h)-SCREEN_HEIGHT2)/SCREEN_HEIGHT2;
- GLfloat vVertices[] = { 0.0f, 0.5f, 0.0f,
- -0.5f, -0.5f, 0.0f,
- 0.5f, -0.5f, 0.0f };
- GLuint vertexPosObject;
- glGenBuffers(1, &vertexPosObject);
- glBindBuffer(GL_ARRAY_BUFFER, vertexPosObject);
- glBufferData(GL_ARRAY_BUFFER, 9*4, vVertices, GL_STATIC_DRAW);
- //glClear ( GL_COLOR_BUFFER_BIT );
- glEnableVertexAttribArray(0);
- glBindBuffer(GL_ARRAY_BUFFER, vertexPosObject);
- glVertexAttribPointer(0 /* ? */, 3, GL_FLOAT, GL_FALSE, 0, 0);
-
- glDrawArrays ( GL_TRIANGLES, 0, 3 );
-
-
-
- /*
- glBegin( GL_QUADS );
- glVertex3f( x1, y2, 0.0f );
- glVertex3f( x2, y2, 0.0f );
- glVertex3f( x2, y1, 0.0f );
- glVertex3f( x1, y1, 0.0f );
- glEnd();
- */
-
-}
-
-
-void RectPX2( int x, int y,int w, int h )
-{
- GLfloat x1 = (1.0f*x-SCREEN_WIDTH2)/SCREEN_WIDTH2;
- GLfloat y1 = (1.0f*y-SCREEN_HEIGHT2)/SCREEN_HEIGHT2;
- GLfloat x2 = (1.0f*(x+w)-SCREEN_WIDTH2)/SCREEN_WIDTH2;
- GLfloat y2 = (1.0f*(y+h)-SCREEN_HEIGHT2)/SCREEN_HEIGHT2;
GLfloat vVertices[] = { x1, y2, 0.0f,
x2, y2, 0.0f,
x2, y1, 0.0f,
@@ -298,8 +249,6 @@ int main_tick() {
int i,j;
SDL_Event event;
SDL_StartTextInput();
- //while (quit == 0)
- //{
while (SDL_PollEvent(&event))
{
@@ -310,25 +259,15 @@ int main_tick() {
quit = 1;
break;
}
- //case SDL_KE
}
-
- //sleep(1);
}
-
-
- //SDL_SetRenderDrawColor(renderer, 0, 100, 0, 0);
- //SDL_RenderClear(renderer);
- //SDL_RenderPresent(renderer);
glClear( GL_COLOR_BUFFER_BIT );
- //glLoadIdentity();
for (i=0;i<=MAX_GENERATION;i++)
{
//rgba32_t c = color_gen_shade(start_col, i, MAX_GENERATION);
rgba32_t c = color_gen_mainlv(start_col, i, MAX_GENERATION);
- //glColor3f( c.r , c.g , c.b );
//static int once=0
for (j=0;j<queue_index;j++)
{
@@ -338,16 +277,12 @@ int main_tick() {
{
koh_node kn = queue_get(j);
printf("j:%d %d %d %d\n",j,kn.x, kn.y, kn.size);
- //RectPX(kn.x, kn.y, kn.size, kn.size);
- RectPX2(kn.x, kn.y, kn.size, kn.size);
- //Triangle(kn.x, kn.y, kn.size, kn.size);
+ RectPX(kn.x, kn.y, kn.size, kn.size);
}
}
}
SDL_GL_SwapWindow( window );
- //SDL_UpdateWindowSurface(window);
- SDL_Delay( 1 );
- //}
+ SDL_Delay( 100 );
#if !__EMSCRIPTEN__
return 0;
@@ -359,13 +294,13 @@ void main_loop()
#if __EMSCRIPTEN__
emscripten_set_main_loop(main_tick, -1, 1);
+ //emscripten_set_main_loop(main_tick, 10, 1);
#else
while (0 == quit)
{
main_tick();
printf("One tick\n");
- //sleep(1);
}
#endif
}
@@ -388,15 +323,12 @@ int main()
SDL_GL_SetSwapInterval( 1 );
//init OpenGL
- //glMatrixMode( GL_PROJECTION );
- //glLoadIdentity();
+
error = glGetError();
if( error != GL_NO_ERROR )
{
printf( "Error initializing OpenGL! \n");
}
- //glMatrixMode( GL_MODELVIEW );
- //glLoadIdentity();
error = glGetError();
if( error != GL_NO_ERROR )
{
@@ -426,7 +358,6 @@ int main()
shaderProgram = glCreateProgram();
glAttachShader(shaderProgram, vertexShader);
glAttachShader(shaderProgram, fragmentShader);
- // glBindFragDataLocation(shaderProgram, 0, "outColor");
glLinkProgram(shaderProgram);
glUseProgram(shaderProgram);
@@ -436,54 +367,6 @@ int main()
glVertexAttribPointer(posAttrib, 3, GL_FLOAT, GL_FALSE, 0, 0);
main_loop();
- /*
- //Enable text input
- SDL_StartTextInput();
- while (quit == 0)
- {
- while (SDL_PollEvent(&event))
- {
-
- switch (event.type)
- {
- case SDL_QUIT:
- {
- quit = 1;
- break;
- }
- //case SDL_KE
- }
-
- //sleep(1);
- }
-
-
- //SDL_SetRenderDrawColor(renderer, 0, 100, 0, 0);
- //SDL_RenderClear(renderer);
- //SDL_RenderPresent(renderer);
-
- glClear( GL_COLOR_BUFFER_BIT );
- //glLoadIdentity();
-
- for (i=0;i<=MAX_GENERATION;i++)
- {
- //rgba32_t c = color_gen_shade(start_col, i, MAX_GENERATION);
- rgba32_t c = color_gen_mainlv(start_col, i, MAX_GENERATION);
- //glColor3f( c.r , c.g , c.b );
- for (j=0;j<queue_index;j++)
- {
- if (koh_queue[j].generaton == i)
- {
- koh_node kn = queue_get(j);
- //printf("%d %d %d\n",kn.x, kn.y, kn.size);
- RectPX(kn.x, kn.y, kn.size, kn.size);
- }
- }
- }
- SDL_GL_SwapWindow( window );
- SDL_Delay( 1 );
- }
- */
//SDL_StopTextInput();
SDL_DestroyRenderer(renderer);