混合的纹理显示良好,但普通的彩色形状却没有 [英] Blended textures show up fine, but ordinary coloured shapes do not

查看:96
本文介绍了混合的纹理显示良好,但普通的彩色形状却没有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,启用Alpha混合会导致我无法绘制常规的彩色形状.绘制所有内容的顺序没有区别.即使唯一绘制的是彩色形状,它仍然不会显示.

For some reason enabling alpha blending results in me not being able to draw run-of-the-mill coloured shapes. The order in which everything is drawn makes no difference. Even if the only thing being drawn is the coloured shape, it still won't show.

禁用Alpha混合可以解决此问题,但是可以禁用Alpha混合(显然).这使我相信问题出在我如何初始化openGL.

Disabling alpha blending fixes this, but disables alpha blending (obviously). This leads me to believe the problem is in how I'm initializing openGL.

纹理对象包含在世界中,已被注释掉.评论"world.run();" out没什么区别,只有禁用alpha混合才有用.

The textured objects are contained in the world, which is commented out. Commenting "world.run();" out makes no difference, only disabling alpha blending does.

public class Core {

int width=800, height=600;

//World world;

public void Start(){

    try {
        Display.setDisplayMode(new DisplayMode(width,height));
        Display.create();
    } catch (LWJGLException e) {
        e.printStackTrace();
        System.exit(0);
    }

    initGL();
    System.out.println("OpenGL version: " + GL11.glGetString(GL11.GL_VERSION));

    boolean Close = Display.isCloseRequested();

    //world = new World(width, height);

    while(!Close){
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

        if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE) || Display.isCloseRequested())
            Close = true;


        //world.run();
        GL11.glColor4d(1, 0, 0, 1);
        GL11.glBegin(GL11.GL_QUADS);
        GL11.glVertex2d(0, 0);
        GL11.glVertex2d(0, 50);
        GL11.glVertex2d(50, 50);
        GL11.glVertex2d(50, 0);
        GL11.glEnd();

        Display.update();
        //Display.sync(60);
    }

}

public void initGL(){
    GL11.glEnable(GL11.GL_TEXTURE_2D);               

    GL11.glClearColor(1.0f, 1.0f, 1.0f, 0.0f);          

        // enable alpha blending
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

        GL11.glViewport(0,0,width,height);

    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, width, height, 0, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
}

public static void main(String args[]){
    Core m = new Core();
    m.Start();
}

}

这是一个2D应用程序,我试图在黑白世界地图的纹理后面绘制元球.

This is for a 2D app where I'm trying to draw metaballs behind the texture of a black-and-white world map.

现成的彩色形状是指以下

Run-of-the-mill coloured shapes refers to the following,

GL11.glColor4d(1, 0, 0, 1);
GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2d(0, 0);
    GL11.glVertex2d(0, 50);
    GL11.glVertex2d(50, 50);
    GL11.glVertex2d(50, 0);
GL11.glEnd();

即使单独绘制,只要启用了Alpha混合,它也不会显示.

Even if drawn on its own, as long as alpha blending is enabled, it won't show up.

更新: world 的构造函数正在加载(但未绘制)纹理.删除该部分代码,即可显示彩色正方形.我推断,只要加载纹理,无论是否显示,都会出现该问题.

UPDATE: The constructor for world was loading (but not drawing) a texture. Removing that part of the code lets the coloured square show up. I have deduced that the problem will occur as long as a texture is loaded, regardless of whether it is displayed or not.

推荐答案

您在initGL中有glEnable(GL_TEXTURE_2D),但是我看不到它在任何地方都被禁用.

You've got glEnable(GL_TEXTURE_2D) in initGL, but I don't see it disabled anywhere.

如果您要绘制未纹理的对象,您知道必须禁用纹理,对吧?

You know you have to disable texturing if you want to draw an untextured object, right?

这篇关于混合的纹理显示良好,但普通的彩色形状却没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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