gpt4 book ai didi

ios - GLSL 着色器编译但不在 Windows 上绘制任何东西

转载 作者:行者123 更新时间:2023-11-29 13:43:31 25 4
gpt4 key购买 nike

我正在尝试将我为 iOS 编写的一些 OpenGL 渲染代码移植到 Windows 应用程序。该代码在 iOS 上运行良好,但在 Windows 上它不绘制任何东西。我已经将问题缩小到这段代码,因为固定功能的东西(例如 glutSolidTorus)绘制得很好,但是当启用着色器时,没有任何效果。

这是渲染代码:

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_INDEX_ARRAY);

// Set the vertex buffer as current
this->vertexBuffer->MakeActive();

// Get a reference to the vertex description to save copying
const AT::Model::VertexDescription & vd = this->vertexBuffer->GetVertexDescription();

std::vector<GLuint> handles;

// Loop over the vertex descriptions
for (int i = 0, stride = 0; i < vd.size(); ++i)
{
// Get a handle to the vertex attribute on the shader object using the name of the current vertex description
GLint handle = shader.GetAttributeHandle(vd[i].first);

// If the handle is not an OpenGL 'Does not exist' handle
if (handle != -1)
{
glEnableVertexAttribArray(handle);
handles.push_back(handle);

// Set the pointer to the vertex attribute, with the vertex's element count,
// the size of a single vertex and the start position of the first attribute in the array
glVertexAttribPointer(handle, vd[i].second, GL_FLOAT, GL_FALSE,
sizeof(GLfloat) * (this->vertexBuffer->GetSingleVertexLength()),
(GLvoid *)stride);

}

// Add to the stride value with the size of the number of floats the vertex attr uses
stride += sizeof(GLfloat) * (vd[i].second);
}

// Draw the indexed elements using the current vertex buffer
glDrawElements(GL_TRIANGLES,
this->vertexBuffer->GetIndexArrayLength(),
GL_UNSIGNED_SHORT, 0);

glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_INDEX_ARRAY);


// Disable the vertexattributearrays
for (int i = 0, stride = 0; i < handles.size(); ++i)
{
glDisableVertexAttribArray(handles[i]);
}

它位于一个以着色器作为参数的函数中,顶点描述是一个成对列表:元素数量的属性句柄。在此功能之外设置制服。在将着色器传递给函数之前,我启用它以供使用。这是两个着色器源:

顶点:

attribute vec3 position;
attribute vec2 texCoord;
attribute vec3 normal;

// Uniforms

uniform mat4 Model;
uniform mat4 View;
uniform mat4 Projection;
uniform mat3 NormalMatrix;


/// OUTPUTS

varying vec2 o_texCoords;
varying vec3 o_normals;

// Vertex Shader

void main()
{
// Do the normal position transform
gl_Position = Projection * View * Model * vec4(position, 1.0);

// Transform the normals to world space
o_normals = NormalMatrix * normal;

// Pass texture coords on for interpolation
o_texCoords = texCoord;
}

片段:

varying vec2 o_texCoords;
varying vec3 o_normals;

/// Fragment Shader

void main()
{
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
}

我正在运行带有着色器语言 1.2 的 OpenGL 2.1。如果有人能给我任何帮助,我将不胜感激。

最佳答案

我听说您在片段着色器中为片段的输出颜色指定了黑色。尝试将其更改为类似

 gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);

并查看场景中的对象是否会被涂上绿色。

关于ios - GLSL 着色器编译但不在 Windows 上绘制任何东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8345874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com