void GBuffer::CreateBuffer() {
	GLuint width = glutGet(GLUT_WINDOW_WIDTH);
	GLuint height = glutGet(GLUT_WINDOW_HEIGHT);
	FBO = CreateFBO();
	positionTex = CreateRenderTexture(width, height, GL_RGBA32F, GL_FLOAT);
	normalTex = CreateRenderTexture(width, height, GL_RGBA16F, GL_FLOAT);
	albedoTex = CreateRenderTexture(width, height, GL_RGBA8, GL_UNSIGNED_BYTE);
	depthTex = CreateRenderTexture(width, height, GL_DEPTH_COMPONENT24, GL_UNSIGNED_BYTE);

	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, positionTex, 0);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, normalTex, 0);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, albedoTex, 0);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTex, 0);
}
Esempio n. 2
0
/**
 * Initializes the render method.
 */
void InitRendering_Slow(unsigned int windowWidth, unsigned int windowHeight)
{
	DeinitRendering_Slow();

	gWindowWidth = windowWidth;
	gWindowHeight = windowHeight;

	glGenFramebuffers(1, &gSceneFBO);

	glBindFramebuffer(GL_FRAMEBUFFER, gSceneFBO);

	// create render target
	CreateRenderTexture( gSceneTexture, windowWidth, windowHeight );

	// bind render target
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gSceneTexture, 0);

	// create depth buffer
	{
		glGenRenderbuffers(1, &gDepthBuffer);
		glBindRenderbuffer(GL_RENDERBUFFER, gDepthBuffer);
		glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, windowWidth, windowHeight);
		glBindRenderbuffer(GL_RENDERBUFFER, 0);
	}

	// bind depth buffer
	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, gDepthBuffer);

	glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
Esempio n. 3
0
void Init(HWND hWnd)
{
    g_hWnd = hWnd;										// Assign the window handle to a global window handle
    GetClientRect(g_hWnd, &g_rRect);					// Assign the windows rectangle to a global RECT
    InitializeOpenGL(g_rRect.right, g_rRect.bottom);	// Init OpenGL with the global rect


/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

    // Here we initialize our multi-texturing functions
    glActiveTextureARB		= (PFNGLACTIVETEXTUREARBPROC)		wglGetProcAddress("glActiveTextureARB");
    glMultiTexCoord2fARB	= (PFNGLMULTITEXCOORD2FARBPROC)		wglGetProcAddress("glMultiTexCoord2fARB");

    // Make sure our multi-texturing extensions were loaded correctly
    if(!glActiveTextureARB || !glMultiTexCoord2fARB)
    {
        // Print an error message and quit.
        MessageBox(g_hWnd, "Your current setup does not support multitexturing", "Error", MB_OK);
        PostQuitMessage(0);
    }

    // Tell OpenGL our light's position
    glLightfv( GL_LIGHT0, GL_POSITION, g_LightPosition );

    // This turns the background to a dark grey/black.
    glClearColor(0.2f, 0.2f, 0.2f, 1.0f);

    // Turn on our light and enable color along with the light
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_COLOR_MATERIAL);

    // Here we allocate memory for our depth texture that will store our light's view.
    // We must set the channels and type for the texture as GL_DEPTH_COMPONENT.
    CreateRenderTexture(g_Texture, SHADOW_WIDTH, SHADOW_HEIGHT, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, SHADOW_ID);

    // Set the camera:		Position		View		 Up Vector
    g_Camera.PositionCamera(0, 9, 12,     0, 2.5, -2,     0, 1, 0);

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *


}
Esempio n. 4
0
/**
 * Create resize FBO.
 */
static void CreateResizeFBO( int captureWidth, int captureHeight )
{
	if ( gResizeFBO != 0 )
	{
		glDeleteFramebuffers(1, &gResizeFBO);
		gResizeFBO = 0;
	}

	if ( gResizeTexture != 0 )
	{
		glDeleteTextures(1, &gResizeTexture);
		gResizeTexture = 0;
	}

	glGenFramebuffers(1, &gResizeFBO);

	glBindFramebuffer(GL_FRAMEBUFFER, gResizeFBO);
				
	CreateRenderTexture( gResizeTexture, captureWidth, captureHeight );

	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gResizeTexture, 0);		

	glBindFramebuffer(GL_FRAMEBUFFER, 0);
}