Exemplo n.º 1
0
void RenderState::applySampler(GLWrapper & gl, GLuint samplerHandle) const
{
	// abort if we don't support anisotropic texture filtering and that's what we're about to set
	if (pname == GL_TEXTURE_MAX_ANISOTROPY_EXT && !GLC_EXT_texture_filter_anisotropic)
		return;

	switch (type)
	{
		case SS_ENUM:
		case SS_INT:
		gl.SamplerParameteri(samplerHandle, pname, param[0]);
		break;

		case SS_FLOAT:
		gl.SamplerParameterf(samplerHandle, pname, fparam[0]);
		break;

		case SS_FLOAT4:
		gl.SamplerParameterfv(samplerHandle, pname, fparam);
		break;

		default:
		assert(!"Invalid sampler state type");
	}
}
Exemplo n.º 2
0
/* Entry point of program */
int main(int argc, char* argv[])
{
    GLWrapper *glw = new GLWrapper(1024, 768, "Lab2: Hello 3D");;

    if (!ogl_LoadFunctions())
    {
        fprintf(stderr, "ogl_LoadFunctions() failed. Exiting\n");
        return 0;
    }

    /* Note it you might want to move this call to the wrapper class */
    glw->setErrorCallback(error_callback);

    glw->setRenderer(display);
    glw->setKeyCallback(keyCallback);
    glw->setMouseCallback(mouseCallback);
    glw->setReshapeCallback(reshape);

    init(glw);

    glw->eventLoop();

    delete(glw);
    return 0;
}
Exemplo n.º 3
0
/* Entry point of program */
int main(int argc, char* argv[])
{
	GLWrapper *glw = new GLWrapper(1024, 768, "Lab2: Hello 3D");;

	if (!ogl_LoadFunctions())
	{
		fprintf(stderr, "ogl_LoadFunctions() failed. Exiting\n");
		return 0;
	}

	glw->setRenderer(display);
	glw->setKeyCallback(keyCallback);
	glw->setReshapeCallback(reshape);

	init(glw);

	glw->eventLoop();

	delete(glw);
	return 0;
}
Exemplo n.º 4
0
void RenderState::apply(GLWrapper & gl) const
{
	static GLenum last_blendequation_rgb = GL_FUNC_ADD;
	static GLenum last_blendequation_alpha = GL_FUNC_ADD;
	static GLenum last_blend_src_rgb = GL_ONE;
	static GLenum last_blend_src_alpha = GL_ONE;
	static GLenum last_blend_dst_rgb = GL_ZERO;
	static GLenum last_blend_dst_alpha = GL_ZERO;

	switch (pname)
	{
		case GL_DEPTH_FUNC:
		gl.DepthFunc(param[0]);
		break;

		case GL_DEPTH_WRITEMASK:
		gl.DepthMask(param[0]);
		break;

		case GL_CULL_FACE_MODE:
		gl.CullFace(param[0]);
		break;

		case GL_FRONT_FACE:
		gl.FrontFace(param[0]);
		break;

		case GL_POLYGON_MODE:
		gl.PolygonMode(param[0]);
		break;

		case GL_POLYGON_OFFSET_FACTOR:
		gl.PolygonOffset(fparam[0], fparam[1]);
		break;

		case GL_SAMPLE_COVERAGE_VALUE:
		gl.SampleCoverage(fparam[0], (fparam[1] != 0));
		break;

		case GL_SAMPLE_MASK_VALUE:
		gl.SampleMaski(0, param[0]);
		break;

		case GL_LINE_SMOOTH_HINT:
		case GL_POLYGON_SMOOTH_HINT:
		case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
		gl.Hint(pname, param[0]);
		break;

		case GL_BLEND_EQUATION_RGB:
		last_blendequation_rgb = param[0];
		gl.BlendEquationSeparate(last_blendequation_rgb, last_blendequation_alpha);
		break;

		case GL_BLEND_EQUATION_ALPHA:
		last_blendequation_alpha = param[0];
		gl.BlendEquationSeparate(last_blendequation_rgb, last_blendequation_alpha);
		break;

		case GL_BLEND_SRC_RGB:
		last_blend_src_rgb = param[0];
		gl.BlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha);
		break;

		case GL_BLEND_SRC_ALPHA:
		last_blend_src_alpha = param[0];
		gl.BlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha);
		break;

		case GL_BLEND_DST_RGB:
		last_blend_dst_rgb = param[0];
		gl.BlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha);
		break;

		case GL_BLEND_DST_ALPHA:
		last_blend_dst_alpha = param[0];
		gl.BlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha);
		break;

		default:
		assert(0 && "Don't know how to apply state variable");
		break;
	}
}
void RenderModelExternalDrawable::draw(GLWrapper & gl) const
{
	if (vao != 0)
	{
		RenderModelExternal::draw(gl);
	}
	else if (vert_array)
	{
		gl.unbindVertexArray();

		const float * verts;
		int vertcount;
		vert_array->GetVertices(verts, vertcount);
		if (verts)
		{
			gl.VertexAttribPointer(VERTEX_POSITION, 3, GL_FLOAT, GL_FALSE, 0, verts);
			gl.EnableVertexAttribArray(VERTEX_POSITION);

			const float * norms;
			int normcount;
			vert_array->GetNormals(norms, normcount);
			if (norms)
			{
				gl.VertexAttribPointer(VERTEX_NORMAL, 3, GL_FLOAT, GL_FALSE, 0, norms);
				gl.EnableVertexAttribArray(VERTEX_NORMAL);
			}
			else
				gl.DisableVertexAttribArray(VERTEX_NORMAL);

			gl.DisableVertexAttribArray(VERTEX_TANGENT);
			gl.DisableVertexAttribArray(VERTEX_BITANGENT);
			gl.DisableVertexAttribArray(VERTEX_COLOR);

			const float * tc[1];
			int tccount[1];
			if (vert_array->GetTexCoordSets() > 0)
			{
				// TODO: make this work for UV1 and UV2
				vert_array->GetTexCoords(0, tc[0], tccount[0]);
				assert(tc[0]);
				gl.VertexAttribPointer(VERTEX_UV0, 2, GL_FLOAT, GL_FALSE, 0, tc[0]);
				gl.EnableVertexAttribArray(VERTEX_UV0);
			}
			else
				gl.DisableVertexAttribArray(VERTEX_UV0);

			gl.DisableVertexAttribArray(VERTEX_UV1);
			gl.DisableVertexAttribArray(VERTEX_UV2);

			const int * faces;
			int facecount;
			vert_array->GetFaces(faces, facecount);

            if (faces)
            {
                gl.DrawElements(GL_TRIANGLES, facecount, GL_UNSIGNED_INT, faces);
            }
            else
            {
                gl.LineWidth(linesize);
                gl.DrawArrays(GL_LINES, 0, vertcount/3);
            }
		}
	}
}