编译程序时遇到问题,我找不到任何错误。有问题的代码和错误消息如下所示:
我的错误讯息:
- 错误2错误C4430:缺少类型说明符 - 假定为int。注意:C ++ 不支持default-int c:\ users \ codasm \ desktop \ nowe projekty \ glfwframework1 \ system.h 9 1 GLFWFramework1
- 错误1错误C2143:语法错误:缺少';'之前 ''c:\ users \ codasm \ desktop \ nowe projekty \ glfwframework1 \ system.h 9 1 GLFWFramework1 *
将我链接到System.h第9行的错误消息,我不明白错误:
Shader* shader;
system.h中:
#ifndef System_h
#define System_h
#include "Core.h"
class System
{
GLFWwindow* window;
Shader* shader;
// GLuint shader;
GLenum error;
GLuint VAO, VBO, TBO;
vector<vec3> vertices;
vector<vec2> uvs;
vector<vec3> normals;
public:
System();
~System();
bool InitWindow();
bool InitExtensions();
bool InitShaders();
bool InitVertices();
bool InitTextures();
bool InitModels();
void Resize(GLFWwindow* window);
void BeginScene();
void EndScene(GLFWwindow* window);
void Display(GLFWwindow*);
void Run();
void ShutdownWindow();
void ShutdownShaders();
void ShutdownVertices();
void ShutdownTextures();
};
static void KeyPress(GLFWwindow* window, int key, int scancode, int action, int mods);
static void ErrorProc(int error, const char* description);
#endif
Shader.cpp:
#pragma once
#include "Core.h"
class Shader
{
GLuint shader;
public:
Shader(void);
~Shader(void);
bool ConfigureShaders(string vsName, string fsName);
void SetShaderVar(string name, mat4 MVP);
void EnableShader(bool enable);
GLuint GetShader();
};
Shader.h:
#include "Shader.h"
Shader::Shader(void)
{
}
Shader::~Shader(void)
{
}
bool Shader::ConfigureShaders(string vsName, string fsName)
{
// Wielkosc buforow na bledy moze powodowac problemy w przypadku dluzszych komunikatow
// Utworz Shadery
GLuint VS = glCreateShader(GL_VERTEX_SHADER);
GLuint FS = glCreateShader(GL_FRAGMENT_SHADER);
// Czytaj Shadery
string LineBuffer;
fstream VSFile(vsName.c_str(),ios::in);
string VSSource;
if(VSFile.is_open())
{
while(getline(VSFile,LineBuffer))
VSSource += "\n"+LineBuffer;
VSFile.close();
}
fstream FSFile(fsName.c_str(),ios::in);
string FSSource;
if(FSFile.is_open())
{
LineBuffer.clear();
while(getline(FSFile,LineBuffer))
FSSource += "\n"+LineBuffer;
FSFile.close();
}
GLint result;
// int infoLogLength;
// Wprowadz, Kompiluj i Sprawdz Shadery
char const* VSSrc = VSSource.c_str();
glShaderSource(VS,1,&VSSrc,NULL);
glCompileShader(VS);
glGetShaderiv(VS,GL_COMPILE_STATUS,&result);
// glGetShaderiv(VS,GL_INFO_LOG_LENGTH,&infoLogLength);
char VSErrMsg[256];
glGetShaderInfoLog(VS,1024,NULL,VSErrMsg);
cout<<VSErrMsg<<endl;
char const* FSSrc = FSSource.c_str();
glShaderSource(FS,1,&FSSrc,NULL);
glCompileShader(FS);
glGetShaderiv(VS,GL_COMPILE_STATUS,&result);
// glGetShaderiv(VS,GL_INFO_LOG_LENGTH,&infoLogLength);
char FSErrMsg[256];
glGetShaderInfoLog(FS,1024,NULL,FSErrMsg);
cout<<FSErrMsg<<endl;
// Polacz Shadery
shader = glCreateProgram();
glAttachShader(shader,VS);
glAttachShader(shader,FS);
glBindAttribLocation(shader,0,"vertexPos");
glBindAttribLocation(shader,1,"vertexUV");
glLinkProgram(shader);
// Sprawdz Program
glGetProgramiv(shader,GL_LINK_STATUS,&result);
// glGetProgramiv(Shader,GL_INFO_LOG_LENGTH,&infoLogLength);
char PrgErrMsg[256];
glGetProgramInfoLog(shader,1024,NULL,PrgErrMsg);
cout<<PrgErrMsg<<endl;
// Kasuj Shadery
glDeleteShader(VS);
glDeleteShader(FS);
return true;
}
void Shader::SetShaderVar(string name, mat4 MVP)
{
GLuint MatrixLocation = glGetUniformLocation(shader,"MVP");
glUniformMatrix4fv(MatrixLocation,1,GL_FALSE,&MVP[0][0]);
}
void Shader::EnableShader(bool enable)
{
if(!shader)
{
if(enable)
glUseProgram(shader);
else
glUseProgram(0);
}
}
GLuint Shader::GetShader()
{
return shader;
}
答案 0 :(得分:7)
在Shader
中使用之前,您尚未声明System.h
。您似乎可以使用forward declaration
class Shader;
在定义class System
之前,因为你只需要声明一个指向它的指针。如果您需要对类进行任何花哨的操作,那么您需要包含标题以获得完整的定义;但你不需要在这里,所以你不应该。