2
私はOpenGLでプログラミングするのがとても新しく、セグメンテーションフォールトを受け取ってから取り除くことはできません。誰もセグメンテーション違反を見つけてそれを私に説明できますか?glBegin()を入力した後のOpenGLセグメンテーションフォルト
注:これは課題のためのものですが、私は答えを探しているわけではありません。実際に、私は(ただし、次のコードはまた、セグメンテーション違反につながる)にも割り当ての詳細に言及したり、完全なコードを送信しません:
# include <stdio.h>
# include <stdlib.h>
# ifdef __APPLE__
# include <OpenGL/gl.h>
# include <OpenGL/glu.h>
# include <GLUT/glut.h>
# else
# include <GL/gl.h>
# include <GL/glu.h>
# include <GL/freeglut.h>
# endif
# include <iostream>
# include <ctime>
# include <cmath>
using namespace std;
#define GRID 50
/* Eye location */
float eye[]={5,5,5};
void initDefaults(void){
glClearColor(0, 0, 0, 0);
glColor3f(1, 1, 1);
glMatrixMode(GL_PROJECTION);
glFrustum(-10,10,-10,10,0,100);
gluPerspective(45,1,1,100);
}
/* TEMPORARY */
void createGrid(){
//After checking, I narrowed down the segmentation fault to here.
glColor3f(0, 0, 0);
printf("help");
glBegin(GL_POINTS);
glVertex3f(25,25,25);
glEnd();
}
/* displays UI to user */
void display(void){
//Clears the board upon (re)display
glClearColor(1.0,1.0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
//Enables backface culling
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
//Sets up the perspective matrix (viewing/camera)
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(eye[0], eye[1], eye[2], GRID/2, GRID/2, 0, 0, 1, 0);
//I believe the segmentation fault occurs in here.
//************************************
createGrid();
//************************************
//Used for double-buffering
glutSwapBuffers();
}
/* main function - program entry point */
int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitWindowSize(600, 600);
glutInitWindowPosition(200,200);
glutCreateWindow("Terrain");
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA);
glutDisplayFunc(display);
gluOrtho2D(-1, GRID + 1, -1, GRID + 1);
initDefaults();
glutMainLoop();
return(0);
}
シェーダの使用を検討すると、より大きなプロジェクトが可能になります。 freeglutは私の好きなライブラリですbtw;) – Charlie