|
@ -22,75 +22,7 @@ LRESULT CALLBACK GLWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) |
|
|
return DefWindowProc(hwnd, msg, wParam, lParam);//其他消息调用window默认处理函数
|
|
|
return DefWindowProc(hwnd, msg, wParam, lParam);//其他消息调用window默认处理函数
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 创建一个GPU程序 |
|
|
|
|
|
*/ |
|
|
|
|
|
GLuint CreateGPUProgram(const char* vsShaderPath, const char* fsShaderPath) { |
|
|
|
|
|
|
|
|
|
|
|
//创建shader
|
|
|
|
|
|
GLuint vsShader = glCreateShader(GL_VERTEX_SHADER); |
|
|
|
|
|
GLuint fsShader = glCreateShader(GL_FRAGMENT_SHADER); |
|
|
|
|
|
|
|
|
|
|
|
//读取shader代码
|
|
|
|
|
|
const char* vsCode = LoadFileContent(vsShaderPath); |
|
|
|
|
|
const char* fsCode = LoadFileContent(fsShaderPath); |
|
|
|
|
|
|
|
|
|
|
|
//把shader代码 从内存传到显存
|
|
|
|
|
|
glShaderSource(vsShader, 1, &vsCode, nullptr); |
|
|
|
|
|
glShaderSource(fsShader, 1, &fsCode, nullptr); |
|
|
|
|
|
|
|
|
|
|
|
//编译shader
|
|
|
|
|
|
glCompileShader(vsShader); |
|
|
|
|
|
GLint compileResult = GL_TRUE; |
|
|
|
|
|
glGetShaderiv(vsShader, GL_COMPILE_STATUS, &compileResult); |
|
|
|
|
|
if (compileResult == GL_FALSE) { |
|
|
|
|
|
char szLog[1024] = { 0 }; |
|
|
|
|
|
GLsizei logLen = 0;//实际错误日志长度
|
|
|
|
|
|
glGetShaderInfoLog(vsShader, 1024, &logLen, szLog); |
|
|
|
|
|
printf("Compile shader fail error log is : %s \n shader code :\n %s \n ", szLog, vsCode); |
|
|
|
|
|
glDeleteShader(vsShader); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
glCompileShader(fsShader); |
|
|
|
|
|
compileResult = GL_TRUE; |
|
|
|
|
|
glGetShaderiv(fsShader, GL_COMPILE_STATUS, &compileResult); |
|
|
|
|
|
if (compileResult == GL_FALSE) { |
|
|
|
|
|
char szLog[1024] = { 0 }; |
|
|
|
|
|
GLsizei logLen = 0;//实际错误日志长度
|
|
|
|
|
|
glGetShaderInfoLog(fsShader, 1024, &logLen, szLog); |
|
|
|
|
|
printf("Compile shader fail error log is : %s \n shader code :\n %s \n ", szLog, fsCode); |
|
|
|
|
|
glDeleteShader(fsShader); |
|
|
|
|
|
} |
|
|
|
|
|
//创建program
|
|
|
|
|
|
GLuint program = glCreateProgram(); |
|
|
|
|
|
|
|
|
|
|
|
//绑定shader
|
|
|
|
|
|
glAttachShader(program, vsShader); |
|
|
|
|
|
glAttachShader(program, fsShader); |
|
|
|
|
|
|
|
|
|
|
|
//连接
|
|
|
|
|
|
glLinkProgram(program); |
|
|
|
|
|
|
|
|
|
|
|
GLint nResult; |
|
|
|
|
|
glGetProgramiv(program, GL_LINK_STATUS, &nResult); |
|
|
|
|
|
if (nResult == GL_FALSE) { |
|
|
|
|
|
char log[1024] = { 0 }; |
|
|
|
|
|
GLsizei writed = 0; |
|
|
|
|
|
glGetProgramInfoLog(program, 1024, &writed, log); |
|
|
|
|
|
printf("Create CPU program fail error %s\n", log); |
|
|
|
|
|
glDeleteProgram(program); |
|
|
|
|
|
program = 0; |
|
|
|
|
|
} |
|
|
|
|
|
//解绑shader
|
|
|
|
|
|
glDetachShader(program, vsShader); |
|
|
|
|
|
glDetachShader(program, fsShader); |
|
|
|
|
|
|
|
|
|
|
|
//删除shader
|
|
|
|
|
|
glDeleteShader(vsShader); |
|
|
|
|
|
glDeleteShader(fsShader); |
|
|
|
|
|
|
|
|
|
|
|
return program; |
|
|
|
|
|
} |
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* @hinstance 本应用程序启动实例 |
|
|
* @hinstance 本应用程序启动实例 |
|
|
* @hPrevInstance 上一次应用程式的实例 |
|
|
* @hPrevInstance 上一次应用程式的实例 |
|
|