PDA

View Full Version : OpenGL draws nothing with Xlib


Fusa
24th July 2005, 06:12 PM
Hi.
I have a problem with my program.

OpenGL program with Xlib doesn't work after upgrade to Fedora Core 4
,which has been working with Fedora Core 3.
It can be compiled and run, but shows only black window, draws nothing.

Does anyone have a advice or similar problems?
Thanks in advance.

///// code /////
#include <iostream>
#include <X11/Xlib.h>
#include <GL/glx.h>
#include <GL/gl.h>
#include <GL/glext.h>
using namespace std;

static int dblBuf[] = {GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1, GLX_DEPTH_SIZE, 12,
GLX_DOUBLEBUFFER, None};

void draw()
{
glClearColor(0.0, 0.0, 0.5, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);

glBegin(GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(0.5, 0.3);
glVertex2f(0.4, 0.4);
glVertex2f(0.9, 0.3);
glEnd();
};

int main(int argc, char **argv)
{
Display* dis = XOpenDisplay(NULL);
XVisualInfo* vi = glXChooseVisual(dis, DefaultScreen(dis), dblBuf);
GLXContext cx = glXCreateContext(dis, vi, None, True);
Window win = XCreateSimpleWindow( dis, RootWindow(dis,0), 0, 0,
300, 300, 3, WhitePixel(dis,0), BlackPixel(dis,0) );
XSetStandardProperties(dis, win, "glxsimple", "glxsimple", None, argv, argc, NULL);

glXMakeCurrent(dis, win, cx);
XMapWindow(dis, win);

draw();
glXSwapBuffers(dis, win);

string tmp;
cout << "Press q to quit." << endl;
cin >> tmp;

return 0;
}

Fusa
25th July 2005, 01:00 PM
I could solve the problem by using XCreateWindow() instead of XCreateSimpleWindow().
Thanks.