derlemeyi açılamıyor Şu anda OpenGL içine girmeye çalışıyorum. Ne yazık ki benim shader'larım her zaman derlemek için başarısız. Gölgelendiricileri saklayan metin dosyaları dizeye başarılı bir şekilde okunur ve glShaderSource - işlevine iletilir. Bu noktaya kadar her şey çalıştığı için, hatamın shader dosyalarının kendisinde bir yerlerde olduğunu düşünüyorum (vertex shader, frag shader). Hata kodunu çıkarmaya çalıştım ama sadece tuhaf semboller alıyorum.OpenGL Shader,
void GLSLProgram::compileShaders(const std::string& vertexShaderFilePath, const std::string& fragmentShaderFilepath)
{
_programID = glCreateProgram();
_vertexShaderID = glCreateShader(GL_VERTEX_SHADER);
_fragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
if (_vertexShaderID == 0){
fatalError("Vertex shader failed to be created !");
}
_fragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
if (_fragmentShaderID == 0){
fatalError("Fragment shader failed to be created !");
}
compileShader(vertexShaderFilePath, _vertexShaderID);
compileShader(fragmentShaderFilepath, _fragmentShaderID);
return;
}
void GLSLProgram::compileShader(const std::string& filePath, GLuint& id)
{
std::ifstream vertexFile(filePath);
if (vertexFile.fail()){
fatalError("Failed to open " + filePath);
perror(filePath.c_str());
}
std::string fileContents = "";
std::string line;
while (std::getline(vertexFile, line)){
fileContents.append(line + '\n');
}
vertexFile.close();
const GLchar* contentsPtr = fileContents.c_str();
glShaderSource(id, 1, &contentsPtr, nullptr);
glCompileShader(id);
GLint success = 0;
glGetShaderiv(id, GL_COMPILE_STATUS, &success); //returns success of most recent compilation
if (success == GL_FALSE)
{
GLint maxLength = 0;
glGetShaderiv(id, GL_INFO_LOG_LENGTH, &maxLength);
// The maxLength includes the NULL character
std::vector<char> errorLog(maxLength);
glGetShaderInfoLog(id, maxLength, &maxLength, &errorLog[0]);
// Provide the infolog in whatever manor you deem best.
// Exit with failure.
glDeleteShader(id); // Don't leak the shader.
std::printf("%s\n", errorLog);
fatalError("shader " + filePath + "failed to compile");
}
}
Fragment shader:
#version 130
out vec3 color;
void main(){
color = vec3(1.0, 0.0, 0.0);
}
Vertex Shader:
#version 130
in vec2 vertexPosition;
void main() {
gl_Position.xy = vertexPosition;
gl_Positionsition.z = 0.0;
gl_Position.w = 1.0;
}
'(std :: get (vertexFile, çizgi)) ise' \ * iç çekme \ * ı bilmek isteriz Herkesin bir kerede hepsini tek tek okumak yerine, dosyaları okumak için aynı çöp kodunu kopyalayıp yapıştırdığı yer. –
@apparatus_icarus: 'GLint maxLength = 0;' Eğer sadece 0-szied bir tampon sağlıyorsanız, GL'den kullanışlı bir hata kaydı alamayacaksınız. Dize sonlandırıcı eklemek için bile yer yok, böylece sadece bazı rasgele verileri yazdırıyorsunuz. – derhass
@derhass MaksLength bildirdikten sonraki satır, bilgi günlüğünün uzunluğuna ayarlanır. – Andreas