Beispiel #1
0
void init(float winwidth, float winheight, float pixratio)
{
    const Vector4 bgcolor = {0.937, 0.937, 0.93, 1.00};
    parg_state_clearcolor(bgcolor);
    parg_state_cullfaces(1);
    parg_state_depthtest(1);
    parg_shader_load_from_asset(SHADER_SIMPLE);

    int* rawdata;
    colorbuf = parg_buffer_slurp_asset(TEXTURE_COLOR, (void*) &rawdata);
    int width = *rawdata++;
    int height = *rawdata++;
    int ncomps = *rawdata++;
    parg_buffer_unlock(colorbuf);

    colortex =
        parg_texture_from_u8(colorbuf, width, height, ncomps, 3 * sizeof(int));
    graybuf = parg_buffer_from_asset(BIN_ISLAND);
    graytex = parg_texture_from_fp32(graybuf, IMGWIDTH, IMGHEIGHT, 1, 0);
    const float h = 1.5f;
    const float w = h * winwidth / winheight;
    const float znear = 10;
    const float zfar = 90;
    projection = M4MakeFrustum(-w, w, -h, h, znear, zfar);
    Point3 eye = {0, -50, 50};
    Point3 target = {0, 0, 0};
    Vector3 up = {0, 1, 0};
    view = M4MakeLookAt(eye, target, up);
    rectmesh = parg_mesh_rectangle(20, 20);
}
Beispiel #2
0
void PezUpdate(float seconds)
{
    const float RadiansPerSecond = 0.5f;
    Globals.Theta += seconds * RadiansPerSecond;
    Globals.Time += seconds;
    
    // Create the model-view matrix:
    Globals.ModelMatrix = M4MakeRotationZYX((Vector3){Globals.Theta, Globals.Theta, Globals.Theta});
    Point3 eye = {0, 0, -80};
    Point3 target = {0, 0, 0};
    Vector3 up = {0, 1, 0};
    Globals.ViewMatrix = M4MakeLookAt(eye, target, up);
    Globals.Modelview = M4Mul(Globals.ViewMatrix, Globals.ModelMatrix);
    Globals.NormalMatrix = M4GetUpper3x3(Globals.Modelview);
}
Beispiel #3
0
void PezUpdate(float seconds)
{
    // Create the model-view matrix:
    Point3 eye = P3MakeFromElems(EyeVector[0] * EyeScale, EyeVector[1] * EyeScale, EyeVector[2] * EyeScale);
    Point3 target = P3MakeFromElems(TargetVector[0] * TargetScale, TargetVector[1] * TargetScale, TargetVector[2] * TargetScale);
    Vector3 up = V3MakeFromElems(0, 1, 0);
    Scene.ViewMatrix = M4MakeLookAt(eye, target, up);

    PezConfig cfg = PezGetConfig();
    const float h = 5.0f;
    const float w = h * cfg.Width / cfg.Height;
    const float hither = 5;
    const float yon = 200;
    Scene.Projection = M4MakeFrustum(-w, w, -h, h, hither, yon);
}
Beispiel #4
0
void PezUpdate(float seconds)
{
    const float RadiansPerSecond = 0.5f;
    Globals.Theta += seconds * RadiansPerSecond;
    
    // Create the model-view matrix:
    Globals.Transforms.Model = M4MakeRotationY(Globals.Theta);
    Point3 eye = {0, 0, 4};
    Point3 target = {0, 0, 0};
    Vector3 up = {0, 1, 0};
    Globals.Transforms.View = M4MakeLookAt(eye, target, up);
    Globals.Transforms.Modelview = M4Mul(Globals.Transforms.View, Globals.Transforms.Model);
    Globals.Transforms.Normal = M4GetUpper3x3(Globals.Transforms.Modelview);
    for (int i = 0; i < 9; ++i) {
        Globals.Transforms.PackedNormal[i] = M3GetElem(Globals.Transforms.Normal, i/3, i%3);
    }
}
void PezInitialize()
{
    const PezConfig cfg = PezGetConfig();

    // Assign the vertex attributes to integer slots:
    GLuint* pAttr = (GLuint*) &Attr;
    for (int a = 0; a < sizeof(Attr) / sizeof(GLuint); a++) {
        *pAttr++ = a;
    }

    // Compile shaders
    Globals.SimpleProgram = LoadProgram("Simple.VS", 0, "Simple.FS");
    Globals.QuadProgram = LoadProgram("Quad.VS", 0, "Quad.FS");
    Globals.GridProgram = LoadProgram("Grid.VS", 0, "Grid.FS");
    Globals.LitProgram = LoadProgram("Lit.VS", "Lit.GS", "Lit.FS");

    // Set up viewport
    float fovy = 16 * TwoPi / 180;
    float aspect = (float) cfg.Width / cfg.Height;
    float zNear = 0.1, zFar = 300;
    Globals.Projection = M4MakePerspective(fovy, aspect, zNear, zFar);
    Point3 eye = {0, 1, 4};
    Point3 target = {0, 0, 0};
    Vector3 up = {0, 1, 0};
    Globals.View = M4MakeLookAt(eye, target, up);

    // Create offscreen buffer:
    Globals.FboHandle = CreateRenderTarget(&Globals.FboTexture);
    glUseProgram(Globals.QuadProgram);
    Globals.QuadVao = CreateQuad();
    Globals.Grid = CreateGrid(GridRows, GridCols);

    // Create geometry
    Globals.Cylinder = CreateCylinder();

    // Misc Initialization
    Globals.Theta = 0;
    glClearColor(0.9, 0.9, 1.0, 1);
    glLineWidth(1.5);
    glEnable(GL_LINE_SMOOTH);
    glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_POLYGON_OFFSET_FILL);
    glPolygonOffset(1,1);
}
Beispiel #6
0
void PezUpdate(unsigned int elapsedMicroseconds)
{
    const float RadiansPerMicrosecond = 0.0000005f;
    static float Theta = 0;
    Theta += elapsedMicroseconds * RadiansPerMicrosecond;
    
    Vector3 offset = V3MakeFromElems(0, 0, 0);
    Matrix4 model = M4MakeRotationZ(Theta);
    model = M4Mul(M4MakeTranslation(offset), model);
    model = M4Mul(model, M4MakeTranslation(V3Neg(offset)));

    Point3 eyePosition = P3MakeFromElems(0, 10, 0);
    Point3 targetPosition = P3MakeFromElems(0, 0, 0);
    Vector3 upVector = V3MakeFromElems(0, 0, 1);
    Matrix4 view = M4MakeLookAt(eyePosition, targetPosition, upVector);
    
    ModelviewMatrix = M4Mul(view, model);
}
Beispiel #7
0
void init(float winwidth, float winheight, float pixratio)
{
    resolution = pixratio * winwidth;
    par_shapes_mesh* shape;
    shape = par_shapes_create_cylinder(30, 3);
    float axis[3] = {1, 0, 0};
    par_shapes_rotate(shape, PARG_PI * 0.5, axis);
    cylinder = parg_mesh_from_shape(shape);
    par_shapes_free_mesh(shape);

    shape = par_shapes_create_plane(3, 3);
    par_shapes_scale(shape, 4, 4, 1);
    par_shapes_translate(shape, -2, -2, -1);
    backdrop = parg_mesh_from_shape(shape);
    par_shapes_free_mesh(shape);

    kleingeo = parg_mesh_from_asset(M_KLEIN);
    parg_mesh_send_to_gpu(kleingeo);

    kleintex = parg_texture_from_asset_linear(T_KLEIN);
    abstract = parg_texture_from_asset(T_ABSTRACT);
    logo = parg_texture_from_asset(T_LOGO);
    rust = parg_texture_from_asset(T_RUST);
    billboard = parg_mesh_rectangle(1, 1);
    reflection = parg_framebuffer_create_empty(
        512, 512, PARG_FBO_LINEAR | PARG_FBO_ALPHA | PARG_FBO_DEPTH);

    const Vector4 transparent = {0, 0, 0, 0};
    parg_state_clearcolor(transparent);

    parg_state_depthtest(1);
    parg_state_cullfaces(1);
    parg_shader_load_from_asset(S_SIMPLE);
    const float h = 1.0f;
    const float w = h * winwidth / winheight;
    const float znear = 4;
    const float zfar = 20;
    projection = M4MakeFrustum(-w, w, -h, h, znear, zfar);
    Point3 eye = {0, 1.8, 5};
    Point3 target = {0, 0.7, 0};
    Vector3 up = {0, 1, 0};
    view = M4MakeLookAt(eye, target, up);
    model = M4MakeIdentity();
}