示例#1
0
void DeferredShading::mark_frustums(Slice<const Frustum> fs)
{
	glEnable(GL_STENCIL_TEST);
	glDisable(GL_CULL_FACE);
	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
	glDepthMask(GL_FALSE);
	DEFER {
		glDisable(GL_STENCIL_TEST);
		glEnable(GL_CULL_FACE);
		glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
		glDepthMask(GL_TRUE);
	};
	glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_REPLACE, GL_KEEP);
	glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_KEEP);

	sun_shadow.bind();
	glClear(GL_STENCIL_BUFFER_BIT);

	BIND_SHADER(stencil);
	for (int i = fs.length-1; i >= 0; i--) {
		const Frustum &f = fs[i];
		glStencilFunc(GL_ALWAYS, i+1, 0xFF);
		draw_frustum(f);
	}
}
示例#2
0
void	draw_stuff(const controls& c, float density)
{
	float	mx = c.m_mouse_x - 500.0f;
	float	my = 500.0f - c.m_mouse_y;
	vec3	mouse_pos(mx, my, 0);

	if (c.m_mouse_right)
	{
		// Re-compute light direction.
		s_light_direction = mouse_pos - s_light_arrow_spot;
		s_light_direction.normalize();

		// Direction perpendicular to the light.
		s_light_right = vec3(s_light_direction.y, -s_light_direction.x, 0);

		// Draw a white line to the mouse, so the user can see
		// what they're orbiting around.
		glColor3f(1, 1, 1);
		draw_segment(s_light_arrow_spot, mouse_pos);
	}

	if (c.m_mouse_left_click)
	{
		// Add or delete an occluder.

		// If we're on an occluder, then delete it.
		bool	deleted = false;
		for (int i = 0; i < s_occluders.size(); i++)
		{
			if (s_occluders[i].hit(mouse_pos))
			{
				// Remove this guy.
				s_occluders[i] = s_occluders.back();
				s_occluders.resize(s_occluders.size() - 1);
				deleted = true;
				break;
			}
		}

		if (!deleted)
		{
			// If we didn't delete, then the user want to
			// add an occluder.
			s_occluders.push_back(occluder(mouse_pos, 20));
		}
	}

	draw_light_arrow();
	draw_light_rays(density);
	draw_occluders();

	// Draw a line at the "near clip plane".
	glColor3f(0, 0, 1);
	draw_segment(vec3(-1000, s_viewer_y, 0), vec3(1000, s_viewer_y, 0));

	draw_frustum();
}
示例#3
0
void display_observer(float frustum_aspect)
{
	int const win_width  = glutGet(GLUT_WINDOW_WIDTH);
	int const win_height = glutGet(GLUT_WINDOW_HEIGHT);
	float const win_aspect = (float)win_width / (float)win_height;

	glViewport(0, 0, win_width, win_height);
	glClearColor(1, 1, 1, 1);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
#ifdef USE_ORTHO
	glOrtho(-10*win_aspect, 10*win_aspect, -10, 10, 0, 100);
#else
	gluPerspective(60, win_aspect, 1, 50);
#endif

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	if(1) {
		glTranslatef(0, 0, -10);
		glRotatef(observer.rot.theta, 1, 0, 0);
		glRotatef(observer.rot.phi, 0, 1, 0);
		glTranslatef(0, 0, 2.5);
	} else {
		gluLookAt(3, 1, -5, 0, 0, -2.5, 0, 1, 0);
	}

#if OPTION_MULTISAMPLE
	glEnable(GL_MULTISAMPLE);
#endif

#ifdef GL_DEPTH_CLAMP
	glEnable(GL_DEPTH_CLAMP);
#endif

	glDisable(GL_LIGHTING);
	glDepthMask(GL_TRUE);
	glColor3f(0.,0.,0.);
	draw_frustum(
		frustum.left,
		frustum.right,
		frustum.bottom,
		frustum.top,
		frustum.near,
		frustum.far );

	glEnable(GL_DEPTH_TEST);
	draw_scene();

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glDepthMask(GL_FALSE);
	draw_grid1d(
		0, 0.1, 0,
		1, 0, 0,
		-5, 5, 
		10, -50, 50,
		1, 0.3, 0.3 );
	draw_grid1d(
		0.1, 0, 0,
		0, 1, 0,
		-5, 5, 
		10, -50, 50,
		0.3, 1, 0.3 );
	glDepthMask(GL_TRUE);
	glDisable(GL_BLEND);

	glutSwapBuffers();
}