基本的なopenGLプログラムを実行しようとしています。昨日このコードを実行していましたが、別のマシンで実行していたため、何も表示される前に終了しました。これは私の init() 関数です:
void init()
{
//generate points
const int NumPoints = 5000;
point3 points[NumPoints];
point3 vertices[3] = {point3(-1.0, -1.0, 0.0),
point3(0.0, 1.0, 0.0),
point3(1.0, -1.0, 0.0)};
points[0] = point3(0.0, 0.0, 0.0);
for(int k = 1; k < NumPoints; k++)
{
int j = rand() % 3;
points[k] = (points[k-1]+vertices[j])/2.0;
}
//load shaders and use the resulting shader program
GLuint program = InitShader("shaders/vshader.glsl", "shaders/fshader.glsl");
glUseProgram( program );
//create Vertex-Array object
GLuint aBuffer;
glGenVertexArrays(1, &aBuffer);
glBindVertexArray((GLuint)&aBuffer);
//create Buffer object
GLuint buffer;
//glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(points),
points, GL_STATIC_DRAW);
//initialize the vertex position attribute from the vertex shader
GLuint loc = glGetAttribLocation( program, "vPosition");
glEnableVertexAttribArray( loc );
glVertexAttribPointer( loc, 3, GL_FLOAT, GL_FALSE, 0, 0);
glClearColor( 1.0, 1.0, 1.0, 1.0); // white background
}
これが私のメインです()
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowSize(500, 500);
glutInitWindowPosition(0, 0);
glutDisplayFunc(display);
glutCreateWindow("Program 1");
glewInit();
//do_nothing();
init();
glutMainLoop();
return 0;
}
私はopenglやglutのいくつかを間違っていたと思ったので、問題を特定するためにコメントアウトし始めました. init() 関数全体をコメントアウトすると、X をクリックするまで終了しない素敵な白いボックスを表示できました。init 内のすべての glFunctions を削除することになりましたが、まだ即時終了の問題がありました。結局、加害者は次の行でした。
point3 points[NumPoints];
混乱して、メインに do_nothing() を書きました (上記のコメントアウトを参照):
void do_nothing(){
const int NumPoints = 5000;
point3 points[NumPoints];
return;
}
私は init() の代わりにこれを呼び出しましたが、悲しいかな、プログラムの即時終了です。こんな単純なことでどうしてこんなにも痛みが生じるのか、私には理解できません。
ポイント3:
class point3
{
public:
GLfloat x;
GLfloat y;
GLfloat z;
point3();
point3(GLfloat, GLfloat, GLfloat);
~point3();
point3 operator+ (point3 param);
point3 operator- (point3 param);
point3 operator/ (GLfloat param);
point3 operator* (GLfloat param);
};
//
// constructiors and destructors
//
point3::point3(){
x = 0;
y = 0;
z = 0;
};
point3::point3(GLfloat a, GLfloat b, GLfloat c)
{
x = a;
y = b;
z = c;
}
Win7でMinGW(クラスに必要)でEclipse CDTを使用しています