It’s me again.
I think I’ve found the problem. I’m still not sure how wide-spread it
is (considering Unga’s report). It seems you are not supposed to call
glXMakeCurrent until the desired window had actually appeared on
screen. Waiting for Expose event seems to do the trick.
I don’t see any good places in SDL to hack that in, but I tried a
very-very-very dirty approach and it worked (SDL_ShowWindow and while(1)
{ wait for Expose; } at the very end of X11_CreateWindow).
Here’s a new test program. Toggle the #if 0 to see the difference on
your system if any.
/* gcc -o glxswap glxswap.c -lX11 -lGL */
#include <stdio.h>
#include <stdlib.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <GL/gl.h>
#include <GL/glx.h>
Display *dpy;
Window root;
GLint att[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24,
GLX_DOUBLEBUFFER, None }; XVisualInfo *vi;
Colormap cmap;
XSetWindowAttributes swa;
Window win;
GLXContext glc;
XWindowAttributes gwa;
XEvent xev;
int main(int argc, char *argv[]) {
dpy = XOpenDisplay(NULL);
root = DefaultRootWindow(dpy);
vi = glXChooseVisual(dpy, 0, att);
cmap = XCreateColormap(dpy, root, vi->visual, AllocNone);
swa.colormap = cmap;
swa.event_mask = StructureNotifyMask | ExposureMask;
win = XCreateWindow(dpy, root, 0, 0,
600, 600, 0, vi->depth, InputOutput, vi->visual,
CWColormap | CWEventMask, &swa); XStoreName(dpy, win, "glX red
window");
XMapWindow(dpy, win);
glc = glXCreateContext(dpy, vi, NULL, GL_TRUE);
#if 0
/* Wait for an event before calling glXMakeCurrent */
while(1) {
XNextEvent(dpy, &xev);
if(xev.type == Expose) break;
}
#endif
glXMakeCurrent(dpy, win, glc);
XGetWindowAttributes(dpy, win, &gwa);
glViewport(0, 0, gwa.width, gwa.height);
/* Fill with red */
glClearColor(1.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
/* First one */
glXSwapBuffers(dpy, win);
printf("See any red?\n");
sleep(1);
/* Second one */
glXSwapBuffers(dpy, win);
sleep(1);
glXMakeCurrent(dpy, None, NULL);
glXDestroyContext(dpy, glc);
XDestroyWindow(dpy, win);
XCloseDisplay(dpy);
return 0;
}On Wed, 26 Oct 2011 01:23:57 +0400 Driedfruit <@Driedfruit> wrote:
On Tue, 25 Oct 2011 20:02:31 -0700 (PDT) Unga wrote:
----- Original Message -----
From: Driedfruit <@Driedfruit>
To: sdl at lists.libsdl.org
Cc:
Sent: Tuesday, October 25, 2011 10:57 AM
Subject: [SDL] Very first call to RenderPresent does nothing (X11,
OpenGL)
Hello list,
I’m seeing, a somewhat undesired behavior in SDL 1.3 (HG) using
the X11 video/OpenGL renderer. I’m not sure if it’s my system or
not, I would appreciate if somebody could give this test program
a run.
What I expect: Red screen after the first SDL_Delay call.
What I get: Black screen after the first SDL_Delay call, red
screen after the second one.
I get red screen with the first SDL_RenderPresent() call.
My system is FreeBSD 8.1, xorg-7.5, OpenGL libs from Nvidia with the
Nvidia GPU driver.
What’s your system?
I’m on Linux 2.6.31-i686, xorg-server-1.9.4, OpenGL libs from non-free
Nvidia driver (260.19.29).
Not sure how to correlate our xorg versions tho Questioning it lead
me to this SDL-less test (which produces same results for me):