Esempio n. 1
0
void assignment1_app::startup()
{
	load_shaders();

	glGenVertexArrays(1, &cube_vao);  //glGenVertexArrays(n, &array) returns n vertex array object names in arrays
	glBindVertexArray(cube_vao); //glBindVertexArray(array) binds the vertex array object with name array.

#pragma region Cube Pos Buffer
	glGenBuffers(1, &buffer);
	glBindBuffer(GL_ARRAY_BUFFER, buffer);
	glBufferData(GL_ARRAY_BUFFER,
		sizeof(cube_data),
		cube_data,
		GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
#pragma endregion

#pragma region Cube Color Buffer
	glGenBuffers(1, &colorBuffer);
	glBindBuffer(GL_ARRAY_BUFFER, colorBuffer);
	glBufferData(GL_ARRAY_BUFFER,
		sizeof(color_data),
		color_data,
		GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
#pragma endregion

#pragma region Cube Normals Buffer
	glGenBuffers(1, &normalsBuffer);
	glBindBuffer(GL_ARRAY_BUFFER, normalsBuffer);
	glBufferData(GL_ARRAY_BUFFER,
		sizeof(normals_data),
		normals_data,
		GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
#pragma endregion

#pragma region Buffer For Uniform Block
	glGenBuffers(1, &uniforms_buffer);
	glBindBuffer(GL_UNIFORM_BUFFER, uniforms_buffer);
	glBufferData(GL_UNIFORM_BUFFER, sizeof(uniforms_block), NULL, GL_DYNAMIC_DRAW);
#pragma endregion

	useUniformColor = falseVec;

	glGenVertexArrays(1, &sphere_vao);
	glBindVertexArray(sphere_vao);
	object.load("bin\\media\\objects\\sphere.sbm");

#pragma region OPENGL Settings

	glEnable(GL_CULL_FACE); // Use face culling to see into the room.
	glFrontFace(GL_CW); //glFrontFace(GLenum mode) In a scene composed entirely of opaque closed surfaces, back-facing polygons are never visible.
	glEnable(GL_DEPTH_TEST); //glEnable(GLenum cap) glEnable and glDisable enable and disable various capabilities.
	glDepthFunc(GL_LEQUAL);	//glDepthFunc(GLenum func) specifies the function used to compare each incoming pixel depth value with the depth value present in the depth buffer. 
#pragma endregion

}
Esempio n. 2
0
void bumpmapping_app::startup()
{
    load_shaders();

    glActiveTexture(GL_TEXTURE0);
    textures.color = sb7::ktx::file::load("media/textures/ladybug_co.ktx");
    glActiveTexture(GL_TEXTURE1);
    textures.normals = sb7::ktx::file::load("media/textures/ladybug_nm.ktx");

    object.load("media/objects/ladybug.sbm");
}
Esempio n. 3
0
void phonglighting_app::startup()
{
    load_shaders();

    glGenBuffers(1, &uniforms_buffer);
    glBindBuffer(GL_UNIFORM_BUFFER, uniforms_buffer);
    glBufferData(GL_UNIFORM_BUFFER, sizeof(uniforms_block), NULL, GL_DYNAMIC_DRAW);

    object.load("media/objects/sphere.sbm");

    glEnable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
}
Esempio n. 4
0
void cullindirect_app::startup()
{
    GLuint first, count;

    object.load("media/objects/asteroids.sbm");

    glGenBuffers(1, &buffers.parameters);
    glBindBuffer(GL_PARAMETER_BUFFER_ARB, buffers.parameters);
    glBufferStorage(GL_PARAMETER_BUFFER_ARB, 256, nullptr, 0);

    glGenBuffers(1, &buffers.drawCandidates);
    glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffers.drawCandidates);

    CandidateDraw* pDraws = new CandidateDraw[CANDIDATE_COUNT];

    int i;

    for (i = 0; i < CANDIDATE_COUNT; i++)
    {
        object.get_sub_object_info(i % object.get_sub_object_count(), first, count);
        pDraws[i].sphereCenter = vmath::vec3(0.0f);
        pDraws[i].sphereRadius = 4.0f;
        pDraws[i].firstVertex = first;
        pDraws[i].vertexCount = count;
    }

    glBufferStorage(GL_SHADER_STORAGE_BUFFER, CANDIDATE_COUNT * sizeof(CandidateDraw), pDraws, 0);

    delete [] pDraws;

    glGenBuffers(1, &buffers.drawCommands);
    glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffers.drawCommands);
    glBufferStorage(GL_SHADER_STORAGE_BUFFER, CANDIDATE_COUNT * sizeof(DrawArraysIndirectCommand), nullptr, GL_MAP_READ_BIT);

    glGenBuffers(1, &buffers.modelMatrices);
    glBindBuffer(GL_UNIFORM_BUFFER, buffers.modelMatrices);
    glBufferStorage(GL_UNIFORM_BUFFER, 1024 * sizeof(vmath::mat4), nullptr, GL_MAP_WRITE_BIT);

    glGenBuffers(1, &buffers.transforms);
    glBindBuffer(GL_UNIFORM_BUFFER, buffers.transforms);
    glBufferStorage(GL_UNIFORM_BUFFER, sizeof(TransformBuffer), nullptr, GL_MAP_WRITE_BIT);

    load_shaders();

    overlay.init(128, 50);

    texture = sb7::ktx::file::load("media/textures/rocks.ktx");
}
void pmbstreaming_app::startup()
{
    glGenBuffers(1, &buffer);
    glBindBuffer(GL_UNIFORM_BUFFER, buffer);

    glBufferStorage(GL_UNIFORM_BUFFER,
                    BUFFER_SIZE,
                    nullptr,
                    GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT);
    vs_uniforms = (MATRICES*)glMapBufferRange(GL_UNIFORM_BUFFER,
                                   0,
                                   BUFFER_SIZE,
                                   GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT);

    GLuint shaders[2] =
    {
        sb7::shader::load("media/shaders/pmbstreaming/pmbstreaming.vs.glsl", GL_VERTEX_SHADER),
        sb7::shader::load("media/shaders/pmbstreaming/pmbstreaming.fs.glsl", GL_FRAGMENT_SHADER)
    };

    program = sb7::program::link_from_shaders(shaders, 2, true);

    object.load("media/objects/torus_nrms_tc.sbm");

    glBindBufferBase(GL_UNIFORM_BUFFER, 0, buffer);

    overlay.init(128, 50);

    glActiveTexture(GL_TEXTURE0);
    texture = sb7::ktx::file::load("media/textures/pattern1.ktx");

    for (int i = 0; i < CHUNK_COUNT; i++)
    {
        fence[i] = 0;
    }
}