Beispiel #1
0
void App::Draw()
{
	IVec2 scrSize = systemMisc.GetScreenSize();
	float f = 1000;
	float n = 1;
	float aspect = (float)scrSize.x / scrSize.y;
	Mat proj = perspectiveLH(45.0f * (float)M_PI / 180.0f, aspect, n, f);
	matrixMan.Set(MatrixMan::PROJ, proj);

	rt.BeginRenderToThis();

	triangle.Draw();
	skyMan.Draw();

	rsPostProcess.Apply();
	deviceMan.SetRenderTarget();
	afBindTextureToBindingPoint(rt.GetTexture(), 0);
	afDraw(PT_TRIANGLESTRIP, 4);

	fontMan.Render();
}
Beispiel #2
0
PVScene::PVScene(Scene *scene) {
    glGenVertexArrays(1, &vertexArray);
    glBindVertexArray(vertexArray);

    GLCHECK();

    glGenBuffers(1, &vertexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);

    GLCHECK();

    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);
    glEnableVertexAttribArray(2);
    glEnableVertexAttribArray(3);

    glVertexAttribPointer(0, 3, GL_FLOAT, false, 64, (void *)0);
    glVertexAttribPointer(1, 3, GL_FLOAT, false, 64, (void *)16);
    glVertexAttribPointer(2, 3, GL_FLOAT, false, 64, (void *)32);
    glVertexAttribPointer(3, 2, GL_FLOAT, false, 64, (void *)48);

    GLCHECK();

    std::vector<Vertex> vertices;

    int vertexCount = 0;
    int vertexOffset = 0;
    int curr_material = scene->getTriangles()[0].material_id;

    for (Triangle & tri : scene->getTriangles()) {
        if (curr_material != tri.material_id) {
            addMesh(scene, curr_material, vertexOffset, vertexCount);

            vertexOffset += vertexCount;
            vertexCount = 0;
            curr_material = tri.material_id;
        }

        vertices.push_back(tri.v[0]);
        vertices.push_back(tri.v[1]);
        vertices.push_back(tri.v[2]);

        vertexCount += 3;
    }

    addMesh(scene, curr_material, vertexOffset, vertexCount);

    Camera *camera = scene->getCamera();
    viewMatrix = lookAtLH(camera->getPosition(), camera->getTarget(), camera->getUp());
    projectionMatrix = perspectiveLH(camera->getFOV(), camera->getAspectRatio(), 0.1f, 100.0f);

    GLCHECK();

    glBufferData(GL_ARRAY_BUFFER,
        vertices.size() * sizeof(Vertex),
        &vertices[0],
        GL_DYNAMIC_DRAW);

    GLCHECK();

    glBindVertexArray(0);

    GLCHECK();

    for (int i = 0; i < scene->getNumLights(); i++) {
        PointLight *light = (PointLight *)scene->getLight(i);

        lights.push_back(new PVLight(light->getPosition(), light->getRadiance()));
    }

    shader = new PVShader(vs3d_source, fs3d_source);

    GLCHECK();
}