OpenGL-纹理贴图后无法呈现白色以外的颜色 [英] OpenGL - Unable to render colors other than white after texture mapping

查看:938
本文介绍了OpenGL-纹理贴图后无法呈现白色以外的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试渲染其他具有纹理的多维数据集后渲染彩色的多维数据集.我有多个符合Drawer接口的抽屉"对象,并将每个对GL对象的引用传递给每个实现类的 draw(final GL gl)方法.但是,无论做什么,我似乎都无法渲染彩色立方体.

I'm trying to render a colored cube after rendering other cubes that have textures. I have multiple "Drawer" objects that conform to the Drawer interface, and I pass each a reference to the GL object to the draw( final GL gl ) method of each individual implementing class. However, no matter what I do, I seem unable to render a colored cube.

代码示例:

gl.glDisable(GL.GL_TEXTURE_2D);

gl.glColor3f( 1f, 0f, 0f );
gl.glBegin(GL.GL_QUADS);
// Front Face
Point3f point = player.getPosition();

gl.glNormal3f(0.0f, 0.0f, 1.0f);
//gl.glTexCoord2f(0.0f, 0.0f);

gl.glVertex3f(-point.x - 1.0f, -1.0f, -point.z + 1.0f);
//gl.glTexCoord2f(1.0f, 0.0f);

gl.glVertex3f(-point.x + 1.0f, -1.0f, -point.z + 1.0f);
//continue rendering rest of cube. ...
gl.glEnd();
gl.glEnable(GL.GL_TEXTURE_2D);

我也尝试在每次顶点调用之前抛出glColor3f调用,但这仍然给了我一个白色立方体.怎么了?

I've also tried throwing the glColor3f calls before each vertex call, but that still gives me a white cube. What's up?

推荐答案

您需要确保执行以下操作.

There are a few things you need to make sure you do.

首先,

gl.glEnable(gl.GL_COLOR_MATERIAL);

这将使您可以将颜色应用于顶点. (在调用glColor3f之前执行此操作.)

This will let you apply colors to your vertices. (Do this before your calls to glColor3f.)

如果仍然不能解决问题,请确保正确使用混合(如果完全使用混合).

If this still does not resolve the problem, ensure that you are using blending properly (if you're using blending at all.)

对于大多数应用程序,您可能需要使用

For most applications, you'll probably want to use

gl.glEnable(gl.GL_BLEND);
gl.glBlendFunc(gl.GL_SRC_ALPHA,gl.GL_ONE_MINUS_SRC_ALPHA);

如果这两种方法都不能解决您的问题,则可能需要在代码本节之前向我们提供有关您正在做/设置的更多信息.

If neither of these things solve your problem, you might have to give us some more information about what you're doing/setting up prior to this section of your code.

这篇关于OpenGL-纹理贴图后无法呈现白色以外的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆