当尝试使用GLFW / GLEW在C / C ++中编译GLSL着色器时,出现以下错误:
##view :
class PostDetailView(DetailView):
model = Post
def get_context_data(self, **kwargs):
context = super(PostDetailView, self).get_context_data(**kwargs)
context['comments'] = Comment.objects.filter(post_id=self.object.id).all()
context['comments_number'] = Comment.objects.filter(post_id=self.object.id).count()
context['form'] = CommentForm()
return context
def post(self, request, pk):
form = CommentForm(request.POST)
if form.is_valid():
comment = form.save(commit=False)
comment.post = Post.objects.get(id=pk)
comment.user = request.user
comment.save()
post = Post.objects.get(pk=pk)
post.comments_nmb+=1
post.save()
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
##template:
{% extends "blog/base.html" %}
{% block content %}
<article class="media content-section">
<img class="rounded-circle article-img" src="{{ object.author.profile.image.url }}">
<div class="media-body">
<div class="article-metadata">
<a class="mr-2" href="{% url 'user-posts' object.author.username %}">{{ object.author }}</a>
<small class="text-muted">{{ object.date_posted|date:"F d, Y" }}</small>
{% if object.author == user %}
<div>
<a class="btn btn-secondary btn-sm mt-1 mb-1" href="{% url 'post-update' object.id %}">Update</a>
<a class="btn btn-danger btn-sm mt-1 mb-1" href="{% url 'post-delete' object.id %}">Delete</a>
</div>
{% endif %}
</div>
<h2 class="article-title">{{ object.title }}</h2>
<p class="article-content">{{ object.content }}</p>
<p>{{comments_number}} Comments</p>
{% for comment in comments %}
<div class="media">
<a class="float-left">
<img class="rounded-circle account-img" src="{{ comment.user.profile.image.url }}">
</a>
<div class="media-body">
<h4 class="media-heading ">{{ comment.user.username }}</h4>
{{comment.text}}
</div>
<p class="float-right"><small>{{ comment.date}}</small></p>
</div>
{% endfor %}
</div>
</article>
{% endblock content %}
我遵循了learnopengl.com的教程。该代码运行并显示一个空白的正方形,上面的错误消息被打印到命令行。有什么想法,怎么办?
片段着色器是:
0(12) : error C5052: gl_Position is not accessible in this profile
顶点着色器是:
#version 410
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aColor;
layout (location = 2) in vec2 aTexCoord;
out vec3 ourColor;
out vec2 TexCoord;
void main()
{
gl_Position = vec4(aPos, 1.0);
ourColor = aColor;
TexCoord = aTexCoord;
}
如果您想查看其余的代码,请参考上面的教程链接。
答案 0 :(得分:1)
好像您尝试将片段着色器加载为顶点着色器,反之亦然。 gl_Position
只能在顶点着色器中设置,因为它是每个顶点的属性。不过,以正确的顺序加载着色器应该可以解决该问题。