Example #1
0
// the projection matrix; fov, aspect ratio, near, far
void gr_opengl_set_projection_matrix(float fov, float aspect, float z_near, float z_far)
{
	GL_CHECK_FOR_ERRORS("start of set_projection_matrix()()");
	
	if (GL_rendering_to_texture) {
		glViewport(gr_screen.offset_x, gr_screen.offset_y, gr_screen.clip_width, gr_screen.clip_height);
	} else {
		glViewport(gr_screen.offset_x, (gr_screen.max_h - gr_screen.offset_y - gr_screen.clip_height), gr_screen.clip_width, gr_screen.clip_height);
	}
	
	float clip_width, clip_height;

	clip_height = tan( fov * 0.5f ) * z_near;
	clip_width = clip_height * aspect;

	GL_last_projection_matrix = GL_projection_matrix;

	if (GL_rendering_to_texture) {
		opengl_create_perspective_projection_matrix(&GL_projection_matrix, -clip_width, clip_width, clip_height, -clip_height, z_near, z_far);
	} else {
		opengl_create_perspective_projection_matrix(&GL_projection_matrix, -clip_width, clip_width, -clip_height, clip_height, z_near, z_far);
	}

	GL_CHECK_FOR_ERRORS("end of set_projection_matrix()()");

	GL_htl_projection_matrix_set = 1;
}
Example #2
0
void gr_opengl_start_instance_matrix(const vec3d *offset, const matrix *rotation)
{
	Assert( GL_htl_projection_matrix_set );
	Assert( GL_htl_view_matrix_set );

	if (offset == NULL) {
		offset = &vmd_zero_vector;
	}

	if (rotation == NULL) {
		rotation = &vmd_identity_matrix;	
	}

	GL_CHECK_FOR_ERRORS("start of start_instance_matrix()");

	vec3d axis;
	float ang;
	vm_matrix_to_rot_axis_and_angle(rotation, &ang, &axis);

	GL_model_matrix_stack.push(offset, rotation);

	matrix4 model_matrix = GL_model_matrix_stack.get_transform();
	vm_matrix4_x_matrix4(&GL_model_view_matrix, &GL_view_matrix, &model_matrix);

	GL_CHECK_FOR_ERRORS("end of start_instance_matrix()");

	GL_modelview_matrix_depth++;
}
void gr_opengl_render_primitives_particle(particle_material* material_info, primitive_type prim_type, vertex_layout* layout, int offset, int n_verts, int buffer_handle)
{
	GL_CHECK_FOR_ERRORS("start of gr_opengl_render_primitives_particle()");

	opengl_tnl_set_material_particle(material_info);
	
	opengl_render_primitives(prim_type, layout, n_verts, buffer_handle, offset, 0);

	GL_CHECK_FOR_ERRORS("end of gr_opengl_render_primitives_particle()");
}
void gr_opengl_render_primitives(material* material_info, primitive_type prim_type, vertex_layout* layout, int offset, int n_verts, int buffer_handle, size_t buffer_offset)
{
	GL_CHECK_FOR_ERRORS("start of gr_opengl_render_primitives()");

	opengl_tnl_set_material(material_info, true);

	opengl_render_primitives(prim_type, layout, n_verts, buffer_handle, offset, buffer_offset);

	GL_CHECK_FOR_ERRORS("end of gr_opengl_render_primitives()");
}
void gr_opengl_render_model(model_material* material_info, indexed_vertex_source *vert_source, vertex_buffer* bufferp, size_t texi)
{
	Verify(bufferp != NULL);

	GL_CHECK_FOR_ERRORS("start of render_buffer()");

	buffer_data *datap = &bufferp->tex_buf[texi];

	opengl_render_model_program(material_info, vert_source, bufferp, datap);

	GL_CHECK_FOR_ERRORS("end of render_buffer()");
}
void gr_opengl_render_primitives_distortion(distortion_material* material_info, primitive_type prim_type, vertex_layout* layout, int offset, int n_verts, int buffer_handle)
{
	GL_CHECK_FOR_ERRORS("start of gr_opengl_render_primitives_distortion()");

	opengl_tnl_set_material_distortion(material_info);
	
	glDrawBuffer(GL_COLOR_ATTACHMENT0);
	
	opengl_render_primitives(prim_type, layout, n_verts, buffer_handle, offset, 0);

	GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
	glDrawBuffers(2, buffers);

	GL_CHECK_FOR_ERRORS("start of gr_opengl_render_primitives_distortion()");
}
Example #7
0
void GLRenderWidget::paintGL()
{
    //render to FBO texture
    glBindFramebuffer(GL_FRAMEBUFFER, _fboId);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, render_rgb_texture_id, 0);
	glViewport(0, 0, gl_width, gl_height);
    glClear(GL_COLOR_BUFFER_BIT);

    //rendering to texture
	for(map<string, MqsOpenGlSurface*>::iterator it = _surface.begin(); it != _surface.end(); ++it)
	{
        it->second->render();
	}

    GLSL::useProgram(scene_shader_program);

    //converting resulted rgb texure to yuv via gpgpu
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, render_yuv_texture_id, 0);
    glClear(GL_COLOR_BUFFER_BIT);
    glBindVertexArray(fbo_render_VAO);
    glBindTexture(GL_TEXTURE_2D, render_rgb_texture_id);
    glUniform1i(glGetUniformLocation(scene_shader_program, "render_type"), 1);//yuv render
    glDrawArrays(GL_QUADS, 0, 4);

    //fetching yuv componets
    GLubyte* yuv_y = mapTexureToPBO(render_yuv_texture_id, GL_RED, _yuv_y_pbo);
    GLubyte* yuv_u = mapTexureToPBO(render_yuv_texture_id, GL_GREEN, _yuv_u_pbo);
    GLubyte* yuv_v = mapTexureToPBO(render_yuv_texture_id, GL_BLUE, _yuv_v_pbo);

    //broadcast rendered data to external channel
    emit frameReadyAll((unsigned char*)yuv_y, (unsigned char*)yuv_u, (unsigned char*)yuv_v, gl_width, gl_height);

    //unmap yuv data
    unmapPBO(_yuv_y_pbo);
    unmapPBO(_yuv_u_pbo);
    unmapPBO(_yuv_v_pbo);

    if(is_visible)
	{
        //render to preview viewport
        glBindFramebuffer(GL_FRAMEBUFFER, 0);
        glViewport(0, 0, width(), height());
        glClear(GL_COLOR_BUFFER_BIT);
        glBindTexture(GL_TEXTURE_2D, render_rgb_texture_id);
        glBindVertexArray(fbo_render_VAO);
        glUniform1i(glGetUniformLocation(scene_shader_program, "render_type"), 0);//normal render
        glDrawArrays(GL_QUADS, 0, 4);
	}
    else
    {
        glClear(GL_COLOR_BUFFER_BIT);
    }
    glBindTexture(GL_TEXTURE_2D, 0);

    SwapBuffers(hdc);
    MqsOpenGlSurface::activateShader();
    ++frame_counter;GL_CHECK_FOR_ERRORS();
}
Example #8
0
void gr_opengl_end_projection_matrix()
{
	GL_CHECK_FOR_ERRORS("start of end_projection_matrix()");

	glViewport(0, 0, gr_screen.max_w, gr_screen.max_h);

	GL_last_projection_matrix = GL_projection_matrix;

	// the top and bottom positions are reversed on purpose, but RTT needs them the other way
	if (GL_rendering_to_texture) {
		opengl_create_orthographic_projection_matrix(&GL_projection_matrix, 0, i2fl(gr_screen.max_w), 0, i2fl(gr_screen.max_h), -1.0, 1.0);
	} else {
		opengl_create_orthographic_projection_matrix(&GL_projection_matrix, 0, i2fl(gr_screen.max_w), i2fl(gr_screen.max_h), 0, -1.0, 1.0);
	}

	GL_CHECK_FOR_ERRORS("end of end_projection_matrix()");

	GL_htl_projection_matrix_set = 0;
}
void opengl_set_vsync(int status)
{
	if ( (status < 0) || (status > 1) ) {
		Int3();
		return;
	}

	GL_context->setSwapInterval(status);

	GL_CHECK_FOR_ERRORS("end of set_vsync()");
}
Example #10
0
void GLRenderWidget::createGLContext(QWidget *parent)
{
	PIXELFORMATDESCRIPTOR pfd;
	int format;
	hdc = GetDC((HWND)parent->winId());

	memset(&pfd, 0, sizeof(pfd));
	pfd.nSize = sizeof(pfd);
	pfd.nVersion = 1;
	pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
	pfd.iPixelType = PFD_TYPE_RGBA;
	pfd.cColorBits = 24;
	pfd.cDepthBits = 24;

	format = ChoosePixelFormat(hdc, &pfd);
	if (!format || !SetPixelFormat(hdc, format, &pfd))
	{
			traceerr("Setting pixel format fail (%d)\n", GetLastError());
			return;
	}

	GLContext = wglCreateContext(hdc);
	wglMakeCurrent(hdc, GLContext);

	GL_CHECK_FOR_ERRORS();

	GLenum err = glewInit();

	if (err != GLEW_OK)
	{
		traceerr("OpenGL GLEW is not initialized!");
	}

	char *version = (char*)glGetString(GL_VERSION);
	char *hw_platform = (char*)glGetString(GL_RENDERER);
	char *vendor = (char*)glGetString(GL_VENDOR);

	traceerr("Initializing [%s] OpenGL %s \r\n on %s...", vendor, version, hw_platform);
	GL_CHECK_FOR_ERRORS();
}
Example #11
0
void gr_opengl_set_view_matrix(const vec3d *pos, const matrix *orient)
{
	Assert(GL_htl_projection_matrix_set);
	Assert(GL_modelview_matrix_depth == 1);

	GL_CHECK_FOR_ERRORS("start of set_view_matrix()");

	opengl_create_view_matrix(&GL_view_matrix, pos, orient);
	
	GL_model_matrix_stack.clear();
	GL_model_view_matrix = GL_view_matrix;

	if (Cmdline_env) {
		GL_env_texture_matrix_set = true;

		// setup the texture matrix which will make the the envmap keep lined
		// up properly with the environment

		// r.xyz  <--  r.x, u.x, f.x
		GL_env_texture_matrix[0] = GL_model_view_matrix.a1d[0];
		GL_env_texture_matrix[1] = GL_model_view_matrix.a1d[4];
		GL_env_texture_matrix[2] = GL_model_view_matrix.a1d[8];
		// u.xyz  <--  r.y, u.y, f.y
		GL_env_texture_matrix[4] = GL_model_view_matrix.a1d[1];
		GL_env_texture_matrix[5] = GL_model_view_matrix.a1d[5];
		GL_env_texture_matrix[6] = GL_model_view_matrix.a1d[9];
		// f.xyz  <--  r.z, u.z, f.z
		GL_env_texture_matrix[8] = GL_model_view_matrix.a1d[2];
		GL_env_texture_matrix[9] = GL_model_view_matrix.a1d[6];
		GL_env_texture_matrix[10] = GL_model_view_matrix.a1d[10];

		GL_env_texture_matrix[15] = 1.0f;
	}

	GL_CHECK_FOR_ERRORS("end of set_view_matrix()");

	GL_modelview_matrix_depth = 2;
	GL_htl_view_matrix_set = 1;
}