• Announcements

Archived

This topic is now archived and is closed to further replies.

Programming X Windows

Recommended Posts

Hi, basically i''m looking for any information I can get about creating a window in X Windows in fullscreen mode and then connecting opengl to it so I can draw. Here''s what I have so far as test code: int main(int argc, char *argv[]) { Display *dpy = XOpenDisplay(0); MS_INT nBlack = BlackPixel(dpy, DefaultScreen(dpy)); MS_INT nWhite = WhitePixel(dpy, DefaultScreen(dpy)); Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 1280, 1024, 0, nBlack, nBlack); XMapWindow(dpy, w); GC gc = XCreateGC(dpy, w, 0, 0); XSetForeground(dpy, gc, nWhite); XSelectInput(dpy, w, StructureNotifyMask); for(; { XEvent e; XNextEvent(dpy, &e); if(e.type==MapNotify) break; } XDrawLine(dpy, w, gc, 10, 60, 180, 20); XFlush(dpy); sleep(10); return EXIT_SUCCESS; } How would I make this fullscreen and connect it to OpenGL? Thanks

Share on other sites
quote:

Use SDL

And the problem with X11 programming is what? It really isn''t that much more difficult than Win32 (with the possible exclusion of changing the display mode, which I''ve yet to look into properly). If all he''s doing is creating a gl context and using that then SDL really is overkill. He could also simply be doing for the experience too...

Anyway, this will create an opengl context for you. This is just ripped from my current project so it won''t compile as is, but it should give you the idea.
    // Find the set of GLXFBConfig''s that match    // the required parameters    int attributes[] =    {        GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,        GLX_RENDER_TYPE, GLX_RGBA_BIT,        GLX_DOUBLEBUFFER, True,        GLX_BUFFER_SIZE, (int)Get("BitDepth"),        GLX_DEPTH_SIZE, (int)Get("ZDepth"),        GLX_STENCIL_SIZE, (int)Get("StencilDepth"),        None    };    int numConfigs = 0;    GLXFBConfig *fbConfigs = glXChooseFBConfig(GetXDisplay(),DefaultScreen(GetXDisplay()),attributes,&numConfigs);    if(fbConfigs==NULL) THROW1(DisplayInitFailed,this);    // Get the visual for the GLXFBConfig    XVisualInfo *vInfo = glXGetVisualFromFBConfig(GetXDisplay(),fbConfigs[0]);    XFree(fbConfigs);    if(vInfo==NULL) THROW1(DisplayInitFailed,this);        // Create the context    glcontext = glXCreateContext(GetXDisplay(),&vInfo[0],NULL,True);    XFree(vInfo);    if(!glcontext) THROW1(DisplayInitFailed,this);

One thing I''m not too sure about is the GLX_BUFFER_SIZE attribute. Does this set the total bits for colour information or do I have to use GLX_RED_SIZE, GLX_BLUE_SIZE and GLX_GREEN_SIZE (or whatever they are)>

Share on other sites
Thanks for the replies! I''ll be sure to try your code out in just a moment, that is if I can get glx working heh.

I actually tried using SDL but SDL + KDevelop + FreeBSD != Easy. For some reason its really hard to setup, so oh well.

Besides I don''t really care about my windowing code because I believe that I''m going to leave windowing out of my 3d engine and leave it up to the user to figure out.

Share on other sites
By the way, what about all of the x functions? How am I going to manage keyboard input and stuff?

GLUT

Share on other sites
Are you insane??? GLUT sucks!

Seriously, though, I''ve never directly used X for two reasons: First, I''ve heard it''s not a wonderful interface. Second, and most important, I like my programs to be cross platform. Using any OS-specific code (even if it would still work on various OSes, in this case any UNIX-based system) is not acceptable for me if it is avoidable.

The Artist Formerly Known as CmndrM

http://chaos.webhop.org

Share on other sites
Thats why I''m going to write code for X and Windows which incompasses the only platforms I''m shooting for, UNIX and Window\$.

Share on other sites
i''ve been trying to do the same thing (see http://www.gamedev.net/community/forums/topic.asp?topic_id=171431 for a rather unproductive thread on the subject. I just (5 min ago) found out that on nehe''s site most of the tutorials also have a ''linux/glx'' port, which appears to be what we''re looking for, and appears to support full-screen mode. I have not really tested them yet though, but you might want to look into it.

Marijn

Share on other sites
I recommend that you get Linux 3D Graphics Programming by Norman Lin. It covers everything you want. There''s also a sequel called Advanced Linux 3D Graphics Programming also by Norman Lin. Maybe you should get them both.

Share on other sites
To get SDL working KDevelop all you have to do is under Project/Options/Compiler Options/Linker Flags type sdl-config --libs -lGLU -lGL under additional flags (make sure you use ` next to 1 with ~ on a normal keyboard, not the single quote '' next to Enter).

Share on other sites
BlkSabb: Thanks for the tips! I added them to my Wishlist on Amazon.com B-)

Share on other sites
quote:
Original post by BlkSabb
I recommend that you get Linux 3D Graphics Programming by Norman Lin. It covers everything you want. There''s also a sequel called Advanced Linux 3D Graphics Programming also by Norman Lin. Maybe you should get them both.

I dont. They suck.

Well...no, they dont, but they won''t teach you anything useful about XLib except how to use an example.

If you have SPECIFIC xlib question visit comp.windows.x on the usenet. Some of the people there have a clue (not many, but a few).

If you just want to play get a copy of the Xlib programming manual volume 1 and volume 2 (or visit HERE: http://www.tronche.com/gui/x/xlib/) for a copy of the equivalent of volume 2 with a few extra bits.

Volume 1 is kinda useful, but not very anyway. Volume 2 and the man pages are what you really want.

Finally, last but not least you can download my complete mini-display library which I wrote specifically for the purpose of explaining how xlib works.

It does not handle events at all. You need an additional seperate module to handle the xlib event queue for that.

I''ll post a url to my module when I get home; I dont have a copy of it here I think...

Hrmmm.... and stay the heck away from XImages. They are more effiecent than the GLX implementation for straight 2D rasterisation, BUT way more complex, and architecture dependent. Well...if you wanna have fun, poke me again and I''ll talk about them more, but basically even the ppl on comp.windows.x pretty much suck at using XImages. ^^

• Partner Spotlight

• Forum Statistics

• Total Topics
627689
• Total Posts
2978646

• 13
• 14
• 12
• 10
• 12