시스템 사양 및 작업GL/glx가 올바르게 연결되지 않았습니다.
저는 Code :: Blocks를 Ubuntu 10.10에서 사용하고 OpenGL 및 glx로 놀고 있습니다. 저는 C++을 배움의 과정에 있습니다. 그래서 어떤 코드의 스타일이 실제 좋은 표준을 따르지 않습니다. (그러나 저는 개선 방법에 대한 제안을드립니다. 질문에 대한 답변을)이없는
편집 :
거대한 실현 : OpenGL을 프로젝트 코드 : 블록이 생성 기본값은 C++이 아닌 C입니다. 나는 이것을 지금보고있다.
저는 현재 Code :: Blocks의 기본 OpenGL 프로젝트를 간단한 3D 엔진으로 수정하려고합니다. 저는 현재 오류가 점점 오전 : 나는 위해 #INCLUDE을 주석으로
expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before 'Draw'
즉시 사라 < GL/glx.h>
내가 코드 :: 블록은 '아무튼 어딘가하는 포럼 읽기 기본적으로 usr/include /를 살펴 보겠습니다. 그러나 프로젝트 빌드 옵션에서 컴파일러에 대한 검색 디렉토리에 추가 했으므로 아무 것도 수정하지 않은 것처럼 보입니다.
코드 :
MAIN.CPP :
을 main.c :
#include <time.h>
#include "Draw.h"
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
/*draw init here*/
Draw::Draw renderer = Draw::Draw.getDraw();
printf("Press left mouse button to rotate around X axis\n");
printf("Press middle mouse button to rotate around Y axis\n");
printf("Press right mouse button to rotate around Z axis\n");
printf("Press ESC to quit the application\n");
/* timing variable*/
/* Set it to delay half a second before rendering the first frame*/
clock_t flip_time = clock() + 0.5f * CLOCKS_PER_SEC;
while (1)
{
/* Update models */
/* Draw scene */
/* wait until it's been 1/60th of a second*/
while(clock() < flip_time){}
flip_time = clock() + (1.0f/60.0f) * CLOCKS_PER_SEC;
/* Actually flip the frame */
}
}
Draw.h :
#ifndef DRAW_H
#define DRAW_H
#include <GL/glx.h> /* This is the problem line */
#include <GL/gl.h>
#include <X11/X.h> /* X11 constant (e.g. TrueColor) */
#include <X11/keysym.h>
class Draw
{
public:
static Draw getDraw();
virtual ~Draw();
void update();
void render();
protected:
private:
Draw();
bool init();
/* The singleton*/
static Draw *instance;
static bool exists;
/* X Window values */
Display *dpy;
Window win;
GLboolean doubleBuffer;
/* X Parameters*/
XVisualInfo *vi;
Colormap cmap;
XSetWindowAttributes swa;
GLXContext cx;
XEvent event;
int dummy;
};
#endif // DRAW_H
아니지만 적어도 마지막 Draw.cpp :
#include "Draw.h"
/* Set up the singleton*/
bool Draw::exists = false;
Draw* Draw::instance = NULL;
Draw::Draw()
{
/*TODO: make this constructor */
}
Draw::~Draw()
{
//dtor
}
Draw Draw::getDraw()
{
if(!exists)
{
instance = new Draw();
instance->init();
exists = true; //Thanks mat, This line was accidentally removed with extraneous comments
}
return *instance;
}
bool Draw::init()
{
/* Get the buffers ready */
static int snglBuf[] = {GLX_RGBA, GLX_DEPTH_SIZE, 16, None};
static int dblBuf[] = {GLX_RGBA, GLX_DEPTH_SIZE, 16, GLX_DOUBLEBUFFER, None};
/* Double Buffered is best*/
doubleBuffer = GL_TRUE;
/*TODO: add constructor if it hasn't been constructed already*/
dpy = XOpenDisplay(NULL);
if (dpy == NULL)
{
return false;
}
/* make sure OpenGL's GLX extension supported */
if(!glXQueryExtension(dpy, &dummy, &dummy))
{
return false;
}
/* find an appropriate visual */
/* find an OpenGL-capable RGB visual with depth buffer */
vi = glXChooseVisual(dpy, DefaultScreen(dpy), dblBuf);
if (vi == NULL)
{
vi = glXChooseVisual(dpy, DefaultScreen(dpy), snglBuf);
if (vi == NULL)
{
return false;
}
doubleBuffer = GL_FALSE;
}
/*
TODO: Fix or remove this
if(vi->class != TrueColor)
{
return false;
}
*/
/* create an OpenGL rendering context */
/* create an OpenGL rendering context */
cx = glXCreateContext(dpy, vi, /* no shared dlists */ None,
/* direct rendering if possible */ GL_TRUE);
if (cx == NULL)
{
return false;
}
/* create an X window with the selected visual */
/* create an X colormap since probably not using default visual */
cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone);
swa.colormap = cmap;
swa.border_pixel = 0;
swa.event_mask = KeyPressMask | ExposureMask
| ButtonPressMask | StructureNotifyMask;
win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0,
300, 300, 0, vi->depth, InputOutput, vi->visual,
CWBorderPixel | CWColormap | CWEventMask, &swa);
XSetStandardProperties(dpy, win, "main", "main", None,
NULL, NULL, NULL);
/* bind the rendering context to the window */
glXMakeCurrent(dpy, win, cx);
/* request the X window to be displayed on the screen */
XMapWindow(dpy, win);
/* configure the OpenGL context for rendering */
glEnable(GL_DEPTH_TEST); /* enable depth buffering */
glDepthFunc(GL_LESS); /* pedantic, GL_LESS is the default */
glClearDepth(1.0); /* pedantic, 1.0 is the default */
/* frame buffer clears should be to black */
glClearColor(0.0, 0.0, 0.0, 0.0);
/* set up projection transform */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 10.0);
/* establish initial viewport */
/* pedantic, full window size is default viewport */
glViewport(0, 0, 300, 300);
return true;
}
void Draw::update()
{
/*TODO: Add things to draw here*/
}
void Draw::render()
{
/* actually flip buffers here */
}
여기에 게시하기 전에 많은 의견을 삭제했지만 컴파일 여부에 영향을 미치지 않습니다.
감사합니다.
감사합니다. 첫 번째 실수를 수정하고 코드를 복사하는 동안 생략 한 행을 추가했습니다. 이전에이 페이지를 살펴 봤지만 대신 [this one] (http://www.codeproject.com/KB/cpp/singletonrvs.aspx)을 사용하는 것이 좋습니다. 필자의 패턴이 제대로 작동하는지 다시 한 번 살펴 보겠다.하지만 필자가 작업하고있는 내용을 컴파일하고 테스트 할 수 있다면 알아 내기가 너무 어렵지 않을 것이라고 확신한다. – Jeremy
포인터 대신에 참조를 사용할 수도 있습니다. 대부분의 경우 동일한 이진 코드에서 동일한 효과를 나타내지 만 일부 작업은 약간 더 멋지게 만듭니다. "static Draw getDraw()"를 "Draw & getDraw()"로 변경하십시오. 또한 생성자가 private이기 때문에 거기에서 init을 호출 할 수도 있습니다. - 사이드 노트 : 개인적으로 싱글 톤을 안티 패턴으로 생각합니다. 실제로 사용할 수있는 작은 패턴은 없습니다. 클래스 팩토리는 아마도 IMHO 반 패턴 일 수도 있습니다. – datenwolf