【发布时间】:2016-03-16 10:21:17
【问题描述】:
我在将参数传递给我的函数 Void ShaderCode() 时遇到问题,更具体地说,我收到此错误:
错误 C2440:“正在初始化”:无法从“GLchar”转换为“const” GLchar *'
1> 整数类型到指针的转换 type 需要 reinterpret_cast、C-style cast 或 function-style cast
为了更深入了解这里是我的头文件:
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;
}
【问题讨论】: