Exemplo n.º 1
0
static void oil_backend_opengl_draw_triangles(OILImage *im, OILMatrix *matrix, OILImage *tex, OILVertex *vertices, unsigned int vertices_length, unsigned int *indices, unsigned int indices_length, OILTriangleFlags flags) {
    unsigned int i;
    
    load_matrix(matrix);
    bind_framebuffer(im);
    bind_colorbuffer(tex);
    mark_dirty(im);

    /* if we need to, re-generate the tex mipmaps */
    if (tex) {
        OpenGLPriv *tex_priv = tex->backend_data;
        if (tex_priv->dirty_mipmaps) {
            /* tex colorbuffer is already bound */
            glGenerateMipmap(GL_TEXTURE_2D);
            tex_priv->dirty_mipmaps = 0;
        }
    }
    
    /* set up any drawing flags */
    if (!(flags & OIL_DEPTH_TEST)) {
        glDisable(GL_DEPTH_TEST);
    }

    glBegin(GL_TRIANGLES);
    for (i = 0; i < indices_length; i += 3) {
        OILVertex v0 = vertices[indices[i]];
        OILVertex v1 = vertices[indices[i + 1]];
        OILVertex v2 = vertices[indices[i + 2]];
        
        glTexCoord2f(v0.s, v0.t);
        glColor4f(v0.color.r / 255.0, v0.color.g / 255.0, v0.color.b / 255.0, v0.color.a / 255.0);
        glVertex3f(v0.x, v0.y, v0.z);

        glTexCoord2f(v1.s, v1.t);
        glColor4f(v1.color.r / 255.0, v1.color.g / 255.0, v1.color.b / 255.0, v1.color.a / 255.0);
        glVertex3f(v1.x, v1.y, v1.z);

        glTexCoord2f(v2.s, v2.t);
        glColor4f(v2.color.r / 255.0, v2.color.g / 255.0, v2.color.b / 255.0, v2.color.a / 255.0);
        glVertex3f(v2.x, v2.y, v2.z);
    }
    glEnd();
    
    /* undo our drawing flags */
    if (!(flags & OIL_DEPTH_TEST)) {
        glEnable(GL_DEPTH_TEST);
    }    
}
Exemplo n.º 2
0
static void oil_backend_opengl_clear(OILImage *im) {
    bind_framebuffer(im);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
Exemplo n.º 3
0
static void oil_backend_opengl_load(OILImage *im) {
    bind_framebuffer(im);
    glReadPixels(0, 0, im->width, im->height, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, im->data);
}
Exemplo n.º 4
0
	static
	auto bind(framebuffer_target tgt, framebuffer_name fbo)
	noexcept
	{
		return bind_framebuffer(tgt, fbo);
	}