GLSL Probleme mit Texturcoordinaten.
-
Hallo zusammen.
Ich beschäftige mich gerade mit einer kleinen Übung in OpenGL unter Visual Studio 2015 C++.
Ich habe Probleme mit dem Aufruf von glVertexAttributePointer für meine Texturcoordinaten (Errorcode 1281 "INVALID VALUE".
Erst mal mein Vertex-Shader.
uniform mat4 mVPMatrix; attribute vec2 vUVCoord; varying vec2 uTexCoord; void main() { uTexCoord=vUVCoord; gl_Position=mVPMatrix * gl_Vertex; }
Der betrefende Header:
#pragma once class Plane { public: Plane(GLint Prg); ~Plane(); void Draw(glm::mat4 mVPMatrix,GLuint TextureID); private: GLuint VertexBuffer, IndexBuffer, UVBuffer; GLfloat Vertices[12] = { -.5, .5,-5, .5, .5,-5, .5,-.5,-5, -.5,-.5,-5 }; GLfloat UV[8] = { 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0 }; GLbyte Indices[6] = { 0,1,2, 2,3,0 }; };
Und jetzt der Quelltext:
Der Fehler entsteht in Zeile 73.#include <windows.h> #include <glew.h> #include <iostream> #include <stdio.h> #include <matrix_transform.hpp> #include <type_ptr.hpp> #include "Plane.h" #define BUFFER_OFFSET(i) ((void*)(i)) GLint Shader, mVPMatrixLocation,vUVLocation,sTexturLocation; void CheckError(LPCWSTR text) { GLenum Error = glGetError(); if (Error != GL_NO_ERROR) { MessageBox(NULL, text, L"Error", MB_OK); } } Plane::Plane(GLint Prg) { Shader = Prg; mVPMatrixLocation = glGetUniformLocation(Prg, "mVPMatrix"); CheckError(L"Matrix location error !"); vUVLocation = glGetAttribLocation(Shader, "vUVCoord"); CheckError(L"UV location error !"); sTexturLocation = glGetUniformLocation(Shader, "myTexture"); CheckError(L"Textur location error !"); glGenBuffers(1, &VertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, VertexBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW); glGenBuffers(1, &UVBuffer); glBindBuffer(GL_ARRAY_BUFFER, UVBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(UV), UV, GL_STATIC_DRAW); CheckError(L"Buffer UV error !"); glGenBuffers(1, &IndexBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexBuffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Indices), Indices, GL_STATIC_DRAW); } Plane::~Plane() { glDeleteBuffers(1, &VertexBuffer); glDeleteBuffers(1, &UVBuffer); glDeleteBuffers(1, &IndexBuffer); } void Plane::Draw(glm::mat4 mVPMatrix,GLuint TextureID) { glBindBuffer(GL_ARRAY_BUFFER, VertexBuffer); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0)); //The starting point of the VBO, glBindBuffer(GL_ARRAY_BUFFER, VertexBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexBuffer); CheckError(L"BindBuffer Index"); glUseProgram(Shader); glBindBuffer(GL_ARRAY_BUFFER, UVBuffer); CheckError(L"BindBuffer UV error !"); glVertexAttribPointer(vUVLocation, 2, GL_FLOAT, false, 0, 0); CheckError(L"Attributepointer error !"); glEnableVertexAttribArray(vUVLocation); CheckError(L"Enable UV location error !"); glEnable(GL_TEXTURE_2D); CheckError(L"Enable Texture error !"); glActiveTexture(GL_TEXTURE0); CheckError(L"Activate Texture error !"); glBindTexture(GL_TEXTURE_2D, TextureID); CheckError(L"Bind texture error !"); glUniform1i(sTexturLocation,0); CheckError(L"Texture put to shader error !"); glUniformMatrix4fv(mVPMatrixLocation, 1, GL_FALSE,glm::value_ptr(mVPMatrix)); glDrawElements(GL_TRIANGLES, 12, GL_UNSIGNED_BYTE, 0); CheckError(L"Draw error"); glDisableVertexAttribArray(0); glDisableClientState(GL_ARRAY_BUFFER); }
Ich weiss nicht was da schiefläuft.
Danke .
-
Habe im Fragmentshader statt
varying uTexCoord
varying vTexCoord
angegeben.
Warum sich das mit dem belegen der attribute Variable geschnitten hat weiss ich nicht.
Aber jetzt funzt es.Danke für reinschauen.