Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ OpenGL:调试断言失败 #包括 #包括 #包括 #定义缓冲区偏移量(i)((字符*)NULL+(i)) GLuint shaderProgramID; GLuint vao=0; GLuint vbo; 胶合位置ID,彩色ID; #pragma区域着色器函数 静态字符*读取文件(常量字符*文件名) { //打开文件 FILE*fp=fopen(文件名,“r”); //将文件指针移到文件末尾并确定长度 fseek(fp,0,SEEK_END); 长文件长度=ftell(fp); fseek(fp,0,SEEK_集); char*contents=新字符[文件长度+1]; //零输出存储器 对于(int i=0;i左下角 0.5f,-0.5f,0.0f,//2->右下角 0.0f,0.5f,0.0f};//3->右上角 //颜色 GLfloat colors_0[]={1.0f,0.0,0.0f,1.0f,//0 0.0f,1.0f,0.0f,1.0f,//1 0.0f,0.0f,1.0f,1.0f};//3 //标记->三角形1->0 1 2,三角形2->1 3 2 //胶印标记_0[]={0,1,2,1,3,2}; //读取顶点着色器 char*vertexShaderSourceCode=readFile(“vertexShader.vsh”); //阅读片段着色器 char*fragmentShaderSourceCode=readFile(“fragmentShader.fsh”); //生成顶点着色器 GLuint vertexShaderID=makeVertexShader(vertexShaderSourceCode); //生成片段着色器 GLuint fragmentShaderID=makeFragmentShader(fragmentShaderSourceCode); //生成着色器程序 shaderProgramID=makeShaderProgram(vertexShaderID,fragmentShaderID); printf(“顶点着色器ID为%d\n”,vertexShaderID); printf(“片段着色器ID为%d\n”,fragmentShaderID); printf(“着色器程序ID为%d\n”,shaderProgramID); printf(“SU位置的ID为%d\n”,位置ID); //创建顶点数组对象 glGenVertexArrays(1和vao); //绑定顶点数组对象 glBindVertexArray(vao); //创建顶点缓冲区对象 glGenBuffers(1,&vbo); //绑定顶点缓冲区对象 glBindBuffer(GL_数组_BUFFER,vbo); //为4个顶点创建缓冲区->7个值 glBufferData(GLU数组缓冲区,7*3*sizeof(GLfloat),NULL,GLU静态图); //从缓冲器开始,放置位置数据(4个垂直方向的3个值) glBufferSubData(GL_数组_BUFFER,0,3*3*sizeof(GLfloat),顶点_0); //从放置位置数据后开始,放置颜色数据(4个垂直的4个值) glBufferSubData(GL_数组_BUFFER,3*3*sizeof(GLfloat),3*4*sizeof(GLfloat),颜色_0); //生成索引缓冲区 //glGenBuffers(1和indexBufferID); //绑定缓冲区 //glBindBuffer(GL_元素_数组_缓冲区,indexBufferID); //放置6个标记的索引缓冲区数据 //glBufferData(GLU元素\数组\缓冲区,6*sizeof(GLuint),表示0,GLU静态\绘图); //从着色器获取位置属性 positionID=GLGetAttriblLocation(shaderProgramID,“Svposition”); //从着色器获取颜色属性 colorID=glGetAttribLocation(shaderProgramID,“s_vColor”); //告诉变量在缓冲区中可以在哪里找到它的信息 glvertexattributepointer(位置ID,3,GL_FLOAT,GL_FALSE,0,0); glvertexattributepointer(colorID,4,GL_FLOAT,GL_FALSE,0,缓冲区偏移量(3*3*sizeof(GLfloat)); //告诉程序使用着色器程序 glUseProgram(shaderProgramID); //在着色器中启用位置变量 GlenableVertexAttributeArray(位置ID); //在着色器中启用颜色变量 GlenableVertexAttributeArray(colorID); glutMainLoop(); 返回0; }_C++_Opengl - Fatal编程技术网

C++ OpenGL:调试断言失败 #包括 #包括 #包括 #定义缓冲区偏移量(i)((字符*)NULL+(i)) GLuint shaderProgramID; GLuint vao=0; GLuint vbo; 胶合位置ID,彩色ID; #pragma区域着色器函数 静态字符*读取文件(常量字符*文件名) { //打开文件 FILE*fp=fopen(文件名,“r”); //将文件指针移到文件末尾并确定长度 fseek(fp,0,SEEK_END); 长文件长度=ftell(fp); fseek(fp,0,SEEK_集); char*contents=新字符[文件长度+1]; //零输出存储器 对于(int i=0;i左下角 0.5f,-0.5f,0.0f,//2->右下角 0.0f,0.5f,0.0f};//3->右上角 //颜色 GLfloat colors_0[]={1.0f,0.0,0.0f,1.0f,//0 0.0f,1.0f,0.0f,1.0f,//1 0.0f,0.0f,1.0f,1.0f};//3 //标记->三角形1->0 1 2,三角形2->1 3 2 //胶印标记_0[]={0,1,2,1,3,2}; //读取顶点着色器 char*vertexShaderSourceCode=readFile(“vertexShader.vsh”); //阅读片段着色器 char*fragmentShaderSourceCode=readFile(“fragmentShader.fsh”); //生成顶点着色器 GLuint vertexShaderID=makeVertexShader(vertexShaderSourceCode); //生成片段着色器 GLuint fragmentShaderID=makeFragmentShader(fragmentShaderSourceCode); //生成着色器程序 shaderProgramID=makeShaderProgram(vertexShaderID,fragmentShaderID); printf(“顶点着色器ID为%d\n”,vertexShaderID); printf(“片段着色器ID为%d\n”,fragmentShaderID); printf(“着色器程序ID为%d\n”,shaderProgramID); printf(“SU位置的ID为%d\n”,位置ID); //创建顶点数组对象 glGenVertexArrays(1和vao); //绑定顶点数组对象 glBindVertexArray(vao); //创建顶点缓冲区对象 glGenBuffers(1,&vbo); //绑定顶点缓冲区对象 glBindBuffer(GL_数组_BUFFER,vbo); //为4个顶点创建缓冲区->7个值 glBufferData(GLU数组缓冲区,7*3*sizeof(GLfloat),NULL,GLU静态图); //从缓冲器开始,放置位置数据(4个垂直方向的3个值) glBufferSubData(GL_数组_BUFFER,0,3*3*sizeof(GLfloat),顶点_0); //从放置位置数据后开始,放置颜色数据(4个垂直的4个值) glBufferSubData(GL_数组_BUFFER,3*3*sizeof(GLfloat),3*4*sizeof(GLfloat),颜色_0); //生成索引缓冲区 //glGenBuffers(1和indexBufferID); //绑定缓冲区 //glBindBuffer(GL_元素_数组_缓冲区,indexBufferID); //放置6个标记的索引缓冲区数据 //glBufferData(GLU元素\数组\缓冲区,6*sizeof(GLuint),表示0,GLU静态\绘图); //从着色器获取位置属性 positionID=GLGetAttriblLocation(shaderProgramID,“Svposition”); //从着色器获取颜色属性 colorID=glGetAttribLocation(shaderProgramID,“s_vColor”); //告诉变量在缓冲区中可以在哪里找到它的信息 glvertexattributepointer(位置ID,3,GL_FLOAT,GL_FALSE,0,0); glvertexattributepointer(colorID,4,GL_FLOAT,GL_FALSE,0,缓冲区偏移量(3*3*sizeof(GLfloat)); //告诉程序使用着色器程序 glUseProgram(shaderProgramID); //在着色器中启用位置变量 GlenableVertexAttributeArray(位置ID); //在着色器中启用颜色变量 GlenableVertexAttributeArray(colorID); glutMainLoop(); 返回0; }

C++ OpenGL:调试断言失败 #包括 #包括 #包括 #定义缓冲区偏移量(i)((字符*)NULL+(i)) GLuint shaderProgramID; GLuint vao=0; GLuint vbo; 胶合位置ID,彩色ID; #pragma区域着色器函数 静态字符*读取文件(常量字符*文件名) { //打开文件 FILE*fp=fopen(文件名,“r”); //将文件指针移到文件末尾并确定长度 fseek(fp,0,SEEK_END); 长文件长度=ftell(fp); fseek(fp,0,SEEK_集); char*contents=新字符[文件长度+1]; //零输出存储器 对于(int i=0;i左下角 0.5f,-0.5f,0.0f,//2->右下角 0.0f,0.5f,0.0f};//3->右上角 //颜色 GLfloat colors_0[]={1.0f,0.0,0.0f,1.0f,//0 0.0f,1.0f,0.0f,1.0f,//1 0.0f,0.0f,1.0f,1.0f};//3 //标记->三角形1->0 1 2,三角形2->1 3 2 //胶印标记_0[]={0,1,2,1,3,2}; //读取顶点着色器 char*vertexShaderSourceCode=readFile(“vertexShader.vsh”); //阅读片段着色器 char*fragmentShaderSourceCode=readFile(“fragmentShader.fsh”); //生成顶点着色器 GLuint vertexShaderID=makeVertexShader(vertexShaderSourceCode); //生成片段着色器 GLuint fragmentShaderID=makeFragmentShader(fragmentShaderSourceCode); //生成着色器程序 shaderProgramID=makeShaderProgram(vertexShaderID,fragmentShaderID); printf(“顶点着色器ID为%d\n”,vertexShaderID); printf(“片段着色器ID为%d\n”,fragmentShaderID); printf(“着色器程序ID为%d\n”,shaderProgramID); printf(“SU位置的ID为%d\n”,位置ID); //创建顶点数组对象 glGenVertexArrays(1和vao); //绑定顶点数组对象 glBindVertexArray(vao); //创建顶点缓冲区对象 glGenBuffers(1,&vbo); //绑定顶点缓冲区对象 glBindBuffer(GL_数组_BUFFER,vbo); //为4个顶点创建缓冲区->7个值 glBufferData(GLU数组缓冲区,7*3*sizeof(GLfloat),NULL,GLU静态图); //从缓冲器开始,放置位置数据(4个垂直方向的3个值) glBufferSubData(GL_数组_BUFFER,0,3*3*sizeof(GLfloat),顶点_0); //从放置位置数据后开始,放置颜色数据(4个垂直的4个值) glBufferSubData(GL_数组_BUFFER,3*3*sizeof(GLfloat),3*4*sizeof(GLfloat),颜色_0); //生成索引缓冲区 //glGenBuffers(1和indexBufferID); //绑定缓冲区 //glBindBuffer(GL_元素_数组_缓冲区,indexBufferID); //放置6个标记的索引缓冲区数据 //glBufferData(GLU元素\数组\缓冲区,6*sizeof(GLuint),表示0,GLU静态\绘图); //从着色器获取位置属性 positionID=GLGetAttriblLocation(shaderProgramID,“Svposition”); //从着色器获取颜色属性 colorID=glGetAttribLocation(shaderProgramID,“s_vColor”); //告诉变量在缓冲区中可以在哪里找到它的信息 glvertexattributepointer(位置ID,3,GL_FLOAT,GL_FALSE,0,0); glvertexattributepointer(colorID,4,GL_FLOAT,GL_FALSE,0,缓冲区偏移量(3*3*sizeof(GLfloat)); //告诉程序使用着色器程序 glUseProgram(shaderProgramID); //在着色器中启用位置变量 GlenableVertexAttributeArray(位置ID); //在着色器中启用颜色变量 GlenableVertexAttributeArray(colorID); glutMainLoop(); 返回0; },c++,opengl,C++,Opengl,当我运行程序时,它总是显示如下: 及 谁能帮我解决一下吗?#怎么了 #include <stdio.h> #include <GL\glew.h> #include <GL\freeglut.h> #define BUFFER_OFFSET(i) ((char *)NULL+(i)) GLuint shaderProgramID; GLuint vao = 0; GLuint vbo; GLuint positionID, colorID; #prag

当我运行程序时,它总是显示如下:

谁能帮我解决一下吗?#怎么了
#include <stdio.h>
#include <GL\glew.h>
#include <GL\freeglut.h>

#define BUFFER_OFFSET(i) ((char *)NULL+(i))
GLuint shaderProgramID;
GLuint vao = 0;
GLuint vbo;
GLuint positionID, colorID;

#pragma region SHADER_FUNCTIONS
static char* readFile(const char* fileName)
{
//Open the file
FILE* fp = fopen(fileName, "r");
//Move the file pointer to the end of the file and determining the length
fseek(fp, 0, SEEK_END);
long file_length = ftell(fp);
fseek(fp, 0, SEEK_SET);
char* contents = new char[file_length + 1];

//zero out memory
for (int i = 0; i < file_length + 1; i++)
{
    contents[i] = 0;
}

//Here's the actual read
fread(contents, 1, file_length, fp);
contents[file_length + 1] = '\0';
fclose(fp);
return contents;
}

bool compiledStatus(GLint shaderID){
GLint compiled = 0;
glGetShaderiv(shaderID, GL_COMPILE_STATUS, &compiled);
if (compiled) {
    return true;
}
else {
    GLint logLength;
    glGetShaderiv(shaderID, GL_INFO_LOG_LENGTH, &logLength);
    char* msgBuffer = new char[logLength];
    glGetShaderInfoLog(shaderID, logLength, NULL, msgBuffer);
    printf("%s\n", msgBuffer);
    delete (msgBuffer);
    return false;
}
}

//Takes in source code as string
GLuint makeVertexShader(const char* shaderSource)
{
//Call GL to make a vertex shader and get the ID
GLuint vertexShaderID = glCreateShader(GL_VERTEX_SHADER);

//Bind the provided source code to the shader ID
glShaderSource(vertexShaderID, 1, (const GLchar**)&shaderSource, NULL);

//Compile the vertex Shader
glCompileShader(vertexShaderID);

bool compiledCorrect = compiledStatus(vertexShaderID);
if (compiledCorrect)
{
    return vertexShaderID;
}
return -1;

return vertexShaderID;
}

GLuint makeFragmentShader(const char* shaderSource)
{
//Call GL to make a fragment shader and get the ID
GLuint fragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
//Bind the provided source code to the shader ID
glShaderSource(fragmentShaderID, 1, (const GLchar**)&shaderSource, NULL);
//Compile the fragment Shader
glCompileShader(fragmentShaderID);

bool compiledCorrect = compiledStatus(fragmentShaderID);
if (compiledCorrect)
{
    return fragmentShaderID;
}
return -1;

return fragmentShaderID;
}

#pragma endregion SHADER_FUNCTIONS 

void changeViewport(int w, int h)
{
glViewport(0, 0, w, h);
}

//This is the function we are using each time the window needs to be redrawn
void render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glDrawElements(GL_TRIANGLES, 4, GL_UNSIGNED_INT, NULL);
glDrawArrays(GL_TRIANGLES, 0, 3);
glutSwapBuffers();
}

GLuint makeShaderProgram(GLuint vertextShaderID, GLuint fragmentShaderID)
{
GLuint shaderID = glCreateProgram();
//Attach the vertex shader to the shader program
glAttachShader(shaderID, vertextShaderID);

//Attatch the fragment shader to the shader program
glAttachShader(shaderID, fragmentShaderID);

//Link all the shaders together
glLinkProgram(shaderID);
return shaderID;
}

int main(int argc, char** argv)
{
//Standards
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA);
glutInitWindowSize(800, 600);
glutCreateWindow("Test");
glutReshapeFunc(changeViewport);
glutDisplayFunc(render);
glewInit();

//Verticies
GLfloat vertices_0[] = { -0.5f, -0.5f, 0.0f, //0 -> Bottom Left
    0.5f, -0.5f, 0.0f, //2 -> Bottom Right
    0.0f, 0.5f, 0.0f };//3 -> Top Right
//Colors
GLfloat colors_0[] = { 1.0f, 0.0, 0.0f, 1.0f,//0
    0.0f, 1.0f, 0.0f, 1.0f,//1
    0.0f, 0.0f, 1.0f, 1.0f };//3

//Indicies -> Triangle 1 -> 0 1 2, Traingle 2 -> 1 3 2
//GLuint indicies_0[] = { 0, 1, 2, 1, 3, 2 };


//Read the vertex shader
char* vertexShaderSourceCode = readFile("vertexShader.vsh");

//Read the fragment shader
char* fragmentShaderSourceCode = readFile("fragmentShader.fsh");

//Make Vertex Shader
GLuint vertexShaderID = makeVertexShader(vertexShaderSourceCode);

//Make Fragment Shader
GLuint fragmentShaderID = makeFragmentShader(fragmentShaderSourceCode);

//Make Shader Program
shaderProgramID = makeShaderProgram(vertexShaderID, fragmentShaderID);


printf("Vertex Shader ID is %d\n", vertexShaderID);
printf("Fragment Shader ID is %d\n", fragmentShaderID);
printf("Shader Program ID is %d\n", shaderProgramID);
printf("s_vPosition's ID is %d\n", positionID);

//Create vertex array object
glGenVertexArrays(1, &vao);

//Bind Vertex array object
glBindVertexArray(vao);

//Create vertex buffer object
glGenBuffers(1, &vbo);

//Bind vertex buffer object
glBindBuffer(GL_ARRAY_BUFFER, vbo);

//Create Buffer ->7 Values for 4 vertices
glBufferData(GL_ARRAY_BUFFER, 7 * 3 * sizeof(GLfloat), NULL,         GL_STATIC_DRAW);

//Starting at the beggining of the buffer, place the position data (3 values     for 4 verticies)
glBufferSubData(GL_ARRAY_BUFFER, 0, 3 * 3 * sizeof(GLfloat), vertices_0);

//Starting after the placement of position data, place the color data (4 values for 4 verticies)
glBufferSubData(GL_ARRAY_BUFFER, 3 * 3 * sizeof(GLfloat), 3 * 4 * sizeof(GLfloat), colors_0);

//Generate the index buffer
//glGenBuffers(1, &indexBufferID);

//Bind the buffer
//glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferID);

//Place index buffer data for the 6 indicies
//glBufferData(GL_ELEMENT_ARRAY_BUFFER, 6 * sizeof(GLuint), indicies_0, GL_STATIC_DRAW);

//Get the position attribute from the shader
positionID = glGetAttribLocation(shaderProgramID, "s_vPosition");

//Get the color attribute from the shader
colorID = glGetAttribLocation(shaderProgramID, "s_vColor");

//Tell the variables where they can find its info in the buffer
glVertexAttribPointer(positionID, 3, GL_FLOAT, GL_FALSE, 0, 0);

glVertexAttribPointer(colorID, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(3 * 3 * sizeof(GLfloat)));

//Tell the program to use the shader program
glUseProgram(shaderProgramID);
//Turn on the position variable in the shader
glEnableVertexAttribArray(positionID);
//Turn on the color variable in the shader
glEnableVertexAttribArray(colorID);

glutMainLoop();

return 0;
}