Exemple #1
0
int			triangle(t_all *all)
{
	int	nb;

	if (AH->init_fractal)
		init_first_triangle(all);
	init_triangle(all);
	while (++(AF->iter) <= AF->iter_max)
	{
		color_pixel(all, AF->iter);
		if ((nb = abs(rand() % 3)) == 0)
		{
			AP->x = ((AP->x + AF->x1) / 2.0) + AH->motion;
			AP->y = ((AP->y + AF->y1) / 2.0) - AH->motion;
		}
		else if (nb == 1)
		{
			AP->x = ((AP->x + AF->x2) / 2.0) - AH->motion;
			AP->y = ((AP->y + AF->y2) / 2.0) + AH->motion;
		}
		else if (nb == 2)
		{
			AP->x = ((AP->x + AF->x3) / 2.0) + AH->motion;
			AP->y = ((AP->y + AF->y3) / 2.0) - AH->motion;
		}
	}
	return (0);
}
Exemple #2
0
int main() {
	if (openWindow() == -1) return -1;
	
	init_first_triangle();
	init_small_triangle();
	init_second_triangle();

	glfwSetKeyCallback(keyboard);	
	glfwEnable(GLFW_STICKY_KEYS);

	glClearColor(0.0f, 0.0f, 0.6f, 0.0f);
	
	GLuint first_triangleID = LoadShaders("VertexShader.glsl", "FragmentShader.glsl");
	GLuint second_triangleID = LoadShaders("VertexShader.glsl", "FragmentShader2.glsl");
	GLuint small_triangleID = LoadShaders("VertexShader.glsl", "FragmentShader.glsl");
	
	GLuint vertexbuffer;
	glGenBuffers(1, &vertexbuffer);
	glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);

	do {
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		
		glEnableVertexAttribArray(0);
		glEnableVertexAttribArray(1);

		glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
		glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)36);
		
		draw(first_triangleID, first_triangle, vertexbuffer);
		draw(small_triangleID, small_triangle, vertexbuffer);
		draw(second_triangleID, second_triangle, vertexbuffer);

		glDisableVertexAttribArray(0);
		glDisableVertexAttribArray(1);

		glfwSwapBuffers();
	} while (glfwGetKey(GLFW_KEY_ESC) != GLFW_PRESS && glfwGetWindowParam(GLFW_OPENED));

	glfwTerminate();
	glDeleteBuffers(1, &vertexbuffer);
	glDeleteProgram(first_triangleID);
	glDeleteProgram(second_triangleID);

	return 0;
}