예제 #1
0
bool Texture::createRenderTarget(unsigned int width, unsigned int height, GLboolean depth, int fp, GLboolean linear, GLboolean stencil, int attachments)
{
	render_srf = true;
	
	renderSurface.width = width;
	renderSurface.height = height;
	
	phCreateSurface(&renderSurface,depth,fp,linear,stencil,attachments);
	phCheckFBO();

	glTexId = renderSurface.texture;

	use();
	
//	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
//	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);	

	
	return true;
}
예제 #2
0
void R_FrameBuffer_Init(void)
{
    GLsizei width;
    GLsizei height;

	if(framebuffer_ext == false)
		return;

	if(framebuffer_initialized == true)
		return;

	if (!GLEW_VERSION_2_0)
	{
		Con_Printf("OpenGL 2.0 is required\n");
		Cvar_Set("gl_framebuffer", "0");

		return;
	}

	if (!glewIsSupported("GL_EXT_framebuffer_object"))
	{
		Con_Printf("GL_EXT_framebuffer_object is required\n");
		Cvar_Set("gl_framebuffer", "0");

		return;
	}


	glGetBooleanv(GL_SHADER_COMPILER, &compile_status);
	if (!compile_status && gl_framebuffer.value)
	{
		Con_Printf("Shader compilation support is required\n");
		Cvar_Set("gl_framebuffer", "0");

		return;
	}


	if (!gl_framebuffer.value)
		return;


	// create window surface
    window.fbo = 0;
    window.depth = 0;
    window.width = glwidth;
    window.height = glheight;
    window.clearColor[0] = 0.0f;
    window.clearColor[1] = 0.0f;
    window.clearColor[2] = 0.0f;
    window.clearColor[3] = 0.0f;
    window.viewport.x = 0;
    window.viewport.y = 0;
    window.viewport.width = window.width;
    window.viewport.height = window.height;
    glLoadIdentity();
    glGetFloatv(GL_MODELVIEW_MATRIX, window.modelview);
	glOrtho(0, window.width, window.height, 0, -99999, 99999);
    glGetFloatv(GL_MODELVIEW_MATRIX, window.projection);
    glLoadIdentity();


	// create 3D scene surface
    width = glwidth;
    height = glheight;
    scenebase.width = width;
    scenebase.height = height;
    scenebase.clearColor[0] = 0;
    scenebase.clearColor[1] = 0;
    scenebase.clearColor[2] = 0;
    scenebase.clearColor[3] = 0;
    scenebase.viewport.x = 0;
    scenebase.viewport.y = 0;
    scenebase.viewport.width = width;
    scenebase.viewport.height = height;
    glGetFloatv(GL_MODELVIEW_MATRIX, scenebase.modelview);
    glGetFloatv(GL_MODELVIEW_MATRIX, scenebase.projection);
	phCreateSurface("sourcetex", &scenebase, GL_TRUE, GL_FALSE, GL_TRUE);


	width = width >> 1;
    height = height >> 1;

	// create 3D scene surface (first pass)
    scenepass0.width = width;
    scenepass0.height = height;
    scenepass0.clearColor[0] = 0;
    scenepass0.clearColor[1] = 0;
    scenepass0.clearColor[2] = 0;
    scenepass0.clearColor[3] = 0;
    scenepass0.viewport.x = 0;
    scenepass0.viewport.y = 0;
    scenepass0.viewport.width = width;
    scenepass0.viewport.height = height;
    glGetFloatv(GL_MODELVIEW_MATRIX, scenepass0.modelview);
    glGetFloatv(GL_MODELVIEW_MATRIX, scenepass0.projection);
	phCreateSurface("scenepass0", &scenepass0, GL_FALSE, GL_FALSE, GL_TRUE);

	// create 3D scene surface (second pass)
    scenepass1.width = width;
    scenepass1.height = height;
    scenepass1.clearColor[0] = 0;
    scenepass1.clearColor[1] = 0;
    scenepass1.clearColor[2] = 0;
    scenepass1.clearColor[3] = 0;
    scenepass1.viewport.x = 0;
    scenepass1.viewport.y = 0;
    scenepass1.viewport.width = width;
    scenepass1.viewport.height = height;
    glGetFloatv(GL_MODELVIEW_MATRIX, scenepass1.modelview);
    glGetFloatv(GL_MODELVIEW_MATRIX, scenepass1.projection);
	phCreateSurface("scenepass1", &scenepass1, GL_FALSE, GL_FALSE, GL_TRUE);


	// compile shaders
	passProg = phCompile(passv, passf);

	framebuffer_initialized = true;
}
예제 #3
0
void R_Bloom_Init(void)
{
	int p, c;
	float sum;
    GLsizei width;
    GLsizei height;

	if(framebuffer_ext == false)
		return;

	if(!framebuffer_initialized)
		return;

	if(bloom_initialized == true)
		return;


	// normalize kernel coefficients
    sum = 0;
    for (c = 0; c < KERNEL_SIZE; c++)
        sum += kernel[c];
    for (c = 0; c < KERNEL_SIZE; c++)
        kernel[c] /= sum;


	width = glwidth >> 1;
    height = glheight >> 1;


	// create pass surfaces
    for (p = 0; p < BLOOM_FILTER_COUNT; p++)
    {
        pass0[p].width = width;
        pass0[p].height = height;
        pass0[p].viewport.x = 0;
        pass0[p].viewport.y = 0;
        pass0[p].viewport.width = width;
        pass0[p].viewport.height = height;
        glGetFloatv(GL_MODELVIEW_MATRIX, pass0[p].modelview);
        glGetFloatv(GL_MODELVIEW_MATRIX, pass0[p].projection);
        phCreateSurface(va("bloompass0tex%i", p), pass0 + p, GL_FALSE, GL_FALSE, GL_TRUE);
        width = width >> 1;
        height = height >> 1;
    }

	width = glwidth;
	height = glheight;
	for (p = 0; p < BLOOM_FILTER_COUNT; p++)
    {
        pass1[p].width = width;
        pass1[p].height = height;
        pass1[p].viewport.x = 0;
        pass1[p].viewport.y = 0;
        pass1[p].viewport.width = width;
        pass1[p].viewport.height = height;
        glGetFloatv(GL_MODELVIEW_MATRIX, pass1[p].modelview);
        glGetFloatv(GL_MODELVIEW_MATRIX, pass1[p].projection);
		phCreateSurface(va("bloompass1tex%i", p), pass1 + p, GL_FALSE, GL_FALSE, GL_TRUE);
        width = width >> 1;
        height = height >> 1;
    }


	// compile shaders
	combineProg = phCompile(passv, combine4f);
	filterProg = phCompile(passv, row3f);

	bloom_initialized = true;
}