私はオープンGLの知識を向上させます。まあ、私はひどく失敗します。このチュートリアルと混合された私の研究からのいくつかのコードで単純な三角形をレンダリングしようとすると、クラッシュしました: http://www.opengl-tutorial.org/beginners-tutorials/tutorial-2-the-first-triangle/
なぜ私がクラッシュしたのか(gdbからの情報はなく、glDrawArraysの呼び出しだけでクラッシュが発生します)。64 ビットの lubuntu で実験的な GPU ドライバーを入手しましたが、3D ゲームやその他のコードは動作します。私が間違っているのかわかりません。PS: 私はこれを自分のためにやっています。「宿題」などはありません。
#include <iostream>
#include <GL/glew.h>
#include <GL/freeglut.h>
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/matrix_inverse.hpp>
#include <glm/gtx/rotate_vector.hpp>
#include <glm/gtx/string_cast.hpp>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <stack>
#include <cmath>
#include <sstream>
#include <vector>
GLuint triangleVertexBufferId;
GLuint attribPointer;
void updateGL()
{
// clear buffer, enable transparency
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glEnable( GL_BLEND );
//glBindBuffer(GL_ARRAY_BUFFER, triangleVertexBufferId);
std::cout << "Loop: " << triangleVertexBufferId << std::endl;
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, triangleVertexBufferId);
/*glVertexAttribPointer(
0, // attribute 0. No particular reason for 0, but must match the layout in the shader.
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);*/
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
// swap renderbuffers for smooth rendering //
glutSwapBuffers();
}
void idle()
{
glutPostRedisplay();
}
// Callback function called by GLUT when window size changes
void Reshape(int width, int height)
{
glutPostRedisplay();
}
void Terminate(void)
{
}
int main(int argc, char** argv)
{
std::cout << "Hi" << std::endl;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitContextVersion(3,3);
glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
glutInitContextProfile(GLUT_CORE_PROFILE);
glutInitWindowSize (1024, 768);
glutInitWindowPosition (10, 10);
glutCreateWindow("Exercise 04 - Camera control and projection");
glutCreateMenu(NULL);
glutDisplayFunc(updateGL);
glutReshapeFunc(Reshape);
glutIdleFunc(idle);
atexit(Terminate);
glewInit();
std::vector<glm::vec3> vertices;
std::vector<glm::vec3> normals;
std::vector<glm::vec2> uvs;
std::vector<glm::vec3> triangle_index;
vertices.push_back(glm::vec3(-1.0f,-1.0f,0.0f));
vertices.push_back(glm::vec3(1.0f,-1.0f,0.0f));
vertices.push_back(glm::vec3(0.0f,1.0f,0.0f));
std::cout << "Main: " << triangleVertexBufferId << std::endl;
glGenVertexArrays(1,&triangleVertexBufferId);
glBindVertexArray(triangleVertexBufferId);
GLfloat rawVertexData[vertices.size()*3];
for(unsigned int i = 0; i < vertices.size();i=i+3)
{
rawVertexData[i] = vertices[i].x;
rawVertexData[i+1] = vertices[i].y;
rawVertexData[i+2] = vertices[i].z;
}
glBufferData(GL_ARRAY_BUFFER, vertices.size()*3*sizeof(GLfloat), &rawVertexData[0], GL_STATIC_DRAW);
std::cout << "Main: " << triangleVertexBufferId << std::endl;
glutMainLoop();
return(0);
}