使用LWJGL链接和编译OpenGL 3.3和2.1的着色器 [英] Linking and compiling shaders for OpenGL 3.3 and 2.1 using LWJGL

查看:239
本文介绍了使用LWJGL链接和编译OpenGL 3.3和2.1的着色器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用LWJGL创建OpenGL上下文.我可以使其在我的机器上运行(兼容OpenGL 4.2),并且可以在OpenGL 2.1上对简单的着色器进行更改. 我必须编写与OpenGL 2.1兼容的代码(着色器,或者更确切地说是它们的链接和编译,这似乎是这里的问题).我认为写起来会很容易:

I am using LWJGL to create an OpenGL context. I can get it running on my machine (OpenGL 4.2 compatible) and with changes to the simple shaders also on OpenGL 2.1. I have to write code (the shaders, or rather the linking and compilation of them, seem to be the problem here) that is compatible with OpenGL 2.1. I assumed it would be easy to just write:

Frag着色器:

#version 120

in vec4 pass_Color;

out vec4 out_Color;

void main(void) {
    out_Color = pass_Color;
}

Vert着色器:

#version 120

in vec4 in_Position;
in vec4 in_Color;

out vec4 pass_Color;

uniform mat4 Model;
uniform mat4 View;
uniform mat4 Projection;

void main(void) {
    gl_Position = Projection * View * Model * in_Position;

    pass_Color = in_Color;
}

作为我的着色器的第一行,并将其命名为一天.但是,在一台支持OpenGL 3.3的图形卡的计算机上,这些着色器将不会链接和编译.更改为

as the first line of my shaders and call it a day. However, on one machine with a OpenGL 3.3 supporting graphics card, those shaders would not link and compile. When changed to

#version 330
// - or even -
#version 150

它们链接并编译.我已经阅读了有关兼容性,核心和前向兼容性的信息,并且据我所知,问题可能是OpenGL 3.3机器不支持GLSL 1.20,除非在代码中指示运行兼容上下文(我可能对此措辞有误) ,请纠正我).但我担心,由于2.1并不了解OpenGL配置文件,因此在尝试使用OpenGL配置文件设置上下文之前,我肯定需要进行一些检查.

they do link and compile. I have read about compatibility, core and forward compatibility and as I understand it, the problem could be that GLSL 1.20 is not supported on the OpenGL 3.3 machine unless it is instructed in the code to run a compatibility context (I may be phrasing it wrongly, please correct me). But I worry, since 2.1 does not know about OpenGL profiles, surely I will need to do some checks before attempting to setup the context with one.

即使是这种情况,我也不完全确定如何执行正确的逻辑以确保图形卡限制为OpenGL 2.1(以及相应的GLSL版本)的计算机和较新版本(3.3、4.2,等)也将接受它(使用LWJGL).

Even if this is the case, I am not entirely sure how to do the correct logic to ensure that both machines with graphics cards limited to OpenGL 2.1 (and corresponding GLSL version) and machines with much later versions (3.3, 4.2, etc.) will accept it as well (using the LWJGL).

请注意,我想使代码尽可能保持现代OpenGL".

Please note that I would like to keep the code as "modern OpenGL" as possible.

推荐答案

尝试指定像这样的ogl版本:

Try specifying ogl version like this:

        PixelFormat pixelFormat = new PixelFormat();
        ContextAttribs contextAtrributes = new ContextAttribs(3, 2)
            .withForwardCompatible(true)
            .withProfileCore(true);

        Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
        Display.setTitle(WINDOW_TITLE);
        Display.create(pixelFormat, contextAtrributes);

...因为默认情况下,macs支持最大版本的OpenGL 2.1.在OS X 10.7+上,您可以特别要求提供核心配置文件,该配置文件使您可以访问OpenGL 3.2,但是与Windows和Linux不同,您不能在标准OpenGL配置文件中混合使用OpenGL 3+功能.

...since macs by default support a maximum version of OpenGL 2.1. On OS X 10.7+ you can specifically request the core profile which will give you access to OpenGL 3.2 however unlike Windows and Linux you can't mix OpenGL 3+ features in the standard OpenGL profile.

此处.

这篇关于使用LWJGL链接和编译OpenGL 3.3和2.1的着色器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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