简体   繁体   English

使用Qt5 OpenGL 3.3替换glSecondaryColorPointerEXT

[英]glSecondaryColorPointerEXT replacement using Qt5 OpenGL 3.3

I'm learning OpenGL with Qt5 rewriting some legacy code. 我正在学习用Qt5重写一些旧代码的OpenGL。 They use glSecondaryColorPointerEXT(). 他们使用glSecondaryColorPointerEXT()。 After checking the current support for OpenGL in commonly available video cards I've selected Qt5's class QOpenGLFunctions_3_2_Core to access the OpenGL functions. 在检查了通用视频卡中对OpenGL的当前支持之后,我选择了Qt5的类QOpenGLFunctions_3_2_Core来访问OpenGL函数。

Is there an OpenGL 3.2 version or replacement method for this function? 此功能是否有OpenGL 3.2版本或替换方法?

In OpenGL 3.2 you should be using shaders, furthermore by this point you should avoid legacy features like gl_SecondaryColor . 在OpenGL 3.2中,您应该使用着色器,此外,到此时,您应该避免使用gl_SecondaryColor类的旧功能。 The appropriate replacement for secondary color in a shader-based engine is simply an additional generic vertex attribute. 在基于着色器的引擎中,适当替换第二颜色只是一个附加的通用顶点属性。 I explained a very similar question related to OpenGL ES 2.0, my answer there may be of some help. 我解释了一个与OpenGL ES 2.0相关的非常相似的问题 ,我的回答可能会有帮助。

In short, glVertexPointer (...) , glColorPointer (...) , glSecondaryColorPointer{EXT} (...) are all deprecated in OpenGL 3.0. 简而言之,OpenGL 3.0中已弃用glVertexPointer (...)glColorPointer (...)glSecondaryColorPointer{EXT} (...) In a 3.2 core context, you cannot use them at all. 在3.2核心环境中,您根本无法使用它们。 Thus, you need to learn shaders and glVertexAttribPointer (...) . 因此,您需要学习着色器和glVertexAttribPointer (...)

A vertex shader that uses "primary" and "secondary" vertex colors in core GL 3.2 would look something like this: 在核心GL 3.2中使用“主要”和“次要”顶点颜色的顶点着色器看起来像这样:

#version 150 core

uniform mat4 mvp;

in      vec4 vtx_pos;
in      vec4 vtx_color1;
in      vec4 vtx_color2;

out     vec4 color;

void main (void) {
  gl_Position = mvp * vtx_pos;
  color       = vtx_color1 * vtx_color2; // It is up to you to decide what to do
                                         //   with the primary and secondary
                                         //     colors, this is just for show...
}

You would supply data to vtx_pos, vtx_color1 and vtx_color2 by using glVertexAttribPointer (...) using the attribute location queried from the GLSL vertex shader (after linking). 您可以使用glVertexAttribPointer (...)使用从GLSL顶点着色器查询的属性位置(链接后),将数据提供给vtx_pos,vtx_color1和vtx_color2。 And all this completely does away with the need for a glSecondaryColorPointerEXT (...) . 所有这些完全消除了对glSecondaryColorPointerEXT (...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM