OpenGL,如何设置GLSL版本? [英] OpenGL, how to set up GLSL version?

查看:626
本文介绍了OpenGL,如何设置GLSL版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的系统使用freeglut的OpenGL和GLSL的默认版本是4.1,并且使用glew,它的初始化,着色器编译和链接以及执行都没有问题.

My system's default version for OpenGL and GLSL using freeglut is 4.1, also using glew there is no problem with its initialization, shader compilation and linking, and execution.

当我未指定glutInitContextVersion,glutInitContextFlags或glutInitContextProfile时,此默认版本就会发生,那么我的着色器将正常工作.

This default version happens when I don't specify glutInitContextVersion, glutInitContextFlags or glutInitContextProfile, then my shaders work correct.

无论我对此版本有什么支持,我都想提供一个3.3的替代方案.当我使用glut上下文指定3.3版本时,该应用程序启动时未出现错误,并没有抱怨.我的着色器假定使用的是GLSL 3.3版本,然后我设置了线

Regardless I have support to this version, I would like to provide a 3.3 alternative. When I use the glut context specifying the 3.3 version, the application starts with no errors, glew doesn't complain. My shaders are suppose to use the GLSL 3.3 version, then I set the line

#version 330

但是当编译我的着色器时,OpenGL会抱怨带有无效的枚举消息.我尝试删除此行或将其设置为另一个版本,但仍然收到相同的错误.在正确完成所有初始化之后,我要求使用OpenGL版本,并且获得正确的3.3版本,但对于GLSL版本,仍要使用默认版本4.1.

But when my shaders are compiled, OpenGL complains with an invalid enumerant message. I tried removing this line or setting it to another version but I still get the same error. After all initialization has been properly done, i ask for the OpenGL version and I get the right 3.3, but for the GLSL version am still getting the default 4.1.

glGetString(GL_SHADING_LANGUAGE_VERSION);

如果正确,请更正我,我认为此版本已被着色器代码中的版本行覆盖.我想知道是否还有机会初始化指定GLSL版本的上下文?

Please correct me if am right, I guess this version is overwritten by the version line in the shaders code. I wonder if there is a chance to initialize the context specifying the GLSL version too?

推荐答案

我终于解决了.如果我设置核心配置文件以及兼容模式

I finally solved it. If I set the core profile along with the compatibility mode

glutInitContextProfile(GLUT_CORE_PROFILE | GLUT_COMPATIBILITY_PROFILE);

2.1版的OpenGL命令将无法识别.这与教程中提供的信息背道而驰.无论如何,只需使用3.3或更高版本将GLUT_COMPATIBILITY_PROFILE设置为有效即可.

OpenGL commands from 2.1 version won't be recognized. This goes against the information provided in the tutorials. Anyways by only setting the GLUT_COMPATIBILITY_PROFILE it works, using 3.3 or greater version.

这篇关于OpenGL,如何设置GLSL版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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