我在将参数传递到我的函数Void ShaderCode()中时遇到问题更具体,我收到此错误:
错误C2440:'初始化' :无法转换为' GLchar'到#const; GLchar *' 1>从整数类型转换为指针 type需要reinterpret_cast,C风格的强制转换或函数式强制转换
有关此问题的更多信息,请参阅我的标题文件:
typedef unsigned long Molong;
void CompileFunction();
GLchar ShaderCodeStorage(const char* FilePath);
void ShaderCode(const GLuint &ShaderHandler, char* FilePath);
void CompileShader(const GLuint &ShaderHandler, const char* Response);
Molong getFileLength(std::ifstream& file);
这是我的CPP
#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <fstream>
#include "glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include "glm/gtx/transform2.hpp"
#include "glm/gtc/type_precision.hpp"
#include "glew/glew.h"
#include <gl/GL.h>
#include <gl/GLU.h>
#include "glut.h"
#include "Storage.h"
using namespace std;
void CompileFunction()
{
GLuint MyFirstVertShader = glCreateShader(GL_VERTEX_SHADER);
if (0 == MyFirstVertShader)
{
std::cout << "There was an error making the shader" << std::endl;
exit(1);
}
ShaderCode (MyFirstVertShader, "BasicVert.shader");
// glShaderSource(MyFirstVertShader, 1, CodeArray, NULL);
glCompileShader(MyFirstVertShader);
}
void ShaderCode(const GLuint &ShaderHandler, char* FilePath)
{
const GLchar *ShaderArray = ShaderCodeStorage(FilePath);
glShaderSource(ShaderHandler, 1, &ShaderArray, NULL);
}
GLchar ShaderCodeStorage(const char* FilePath)
{
ifstream infile;
infile.open(FilePath, ios::in);
unsigned long Filelength = getFileLength(infile);
GLchar *ShaderCode = new char[Filelength + 1];
ShaderCode[Filelength] = 0;
}
Molong getFileLength(ifstream& file) {
if (!file.good()) return 0;
file.seekg(0, ios::end);
unsigned long Filelength = file.tellg();
file.seekg(0, ios::beg);
return Filelength;
}
答案 0 :(得分:0)
以下功能是罪魁祸首:(至少有2个问题)
GLchar *ShaderCodeStorage(const char* FilePath)
// 1 Return type should be GLChar *
{
...
ShaderCode[Filelength] = 0;
return ShaderCode; // 2. add return
}
您还在哪里阅读着色器文件的内容?确保填充文件内容。