[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with RGBA Texture in GLX



> 
> 
> Nathi-huesken@gmx.de wrote:
> 
> > I am using GLX to open an OpenGL window.
> > Everything works finde, as long, as I Create Textures
> > using:
> > 
>  >
>
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,Width,Height,0,GL_RGBA,GL_UNSIGNED_BYTE,Data);
> > 
> > But that way I do not have an Alpha-Channel in my Textures (which I
> need!).
> > When I try using GL_RGBA or GL_RGB5_A1 instead of the GL_RGB I get the
> > following error:
> > 
> > Program received signal SIGSEGV, Segmentation fault.
> > [Switching to Thread 1024 (LWP 485)]
> > 0x404891d3 in __nvsym04304 () from /usr/lib/libGLcore.so.1
> > 
> > (That is the output ddd/gdb gave me, if I am just running the Prgramm I
> get
> > an simple Segmentation Fault).
> 
> It's impossible to tell what you are doing wrong without some more
> information.
> 
> Your glTexImage2D command seems perfect to me.
> 
> Most likely, your 'Data' array isn't sized correctly.  In this case, it
> should
> be Width*Height*4 bytes long.
> 
> Try this:
> 
>     {
>       unsigned char FakeData [ Width * Height * 4 ] ;
>      
>
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,Width,Height,0,GL_RGBA,GL_UNSIGNED_BYTE,FakeData);
>     }
> 
> ...in place of the glTexImage2D command you have now.  Does it still
> crash?
> 
> Can you show us more of your program?

I thing you misunderstood! My Data-Format is not the Problem. If I change
the seceond GL_RGB/GL_RGBA (the one telling the Data Format of my Data), it is
not a Problem. But if I change the first one, the System is crashing.

Here is the Intializing code for the Window:

 // Connect to X Server
        dpDisplay = XOpenDisplay(NULL);
        if(dpDisplay == NULL)// Could not open display
        {
                //ERROR
                return 0;
        }
        // GLX extension is supported?
        if(!glXQueryExtension(dpDisplay, NULL, NULL))
        {
                return 0; // Return, if X server haven't GLX
        }

        XF86VidModeModeInfo **modes;
        int modeNum;
        int bestMode=0;
        if(Fullscreen)
        {
                //Get All Modes
                XF86VidModeGetAllModeLines(dpDisplay,
DefaultScreen(dpDisplay), &modeNum, &modes);
                /* save desktop-resolution before switching modes */
                deskMode=*modes[0];
                /* look for mode with requested resolution */
                for (int i = 0; i < modeNum; i++)
                {
                        if ((modes[i]->hdisplay == ScreenWidth) &&
(modes[i]->vdisplay == ScreenHeight))
                        {
                                bestMode = i;
                        }
                }
        }

        int Attr32[] = {        GLX_RGBA,
                                GLX_RED_SIZE, 8,
                                GLX_GREEN_SIZE, 8,
                                GLX_BLUE_SIZE, 8,
                                GLX_ALPHA_SIZE,8,
                                GLX_DEPTH_SIZE, 16,
                                GLX_DOUBLEBUFFER,
                                None};

// Find visual
        XVisualInfo     *xvVisualInfo;

        xvVisualInfo = glXChooseVisual(dpDisplay, DefaultScreen(dpDisplay),
Attr32);
        if(xvVisualInfo == NULL)
        {
                //Error
                return 0; // If Visual info can't be shoosed
        }

        // Create OpenGL rendering context
        glXContext = glXCreateContext(dpDisplay, xvVisualInfo, None, True);
        if(glXContext == NULL)
        {
                return 0; // Can't create rendering context
        }
        Colormap                                cmColorMap;
        XSetWindowAttributes    winAttr;
        // Create new colormap for our window
        cmColorMap = XCreateColormap(dpDisplay, RootWindow(dpDisplay,
xvVisualInfo->screen), xvVisualInfo->visual, AllocNone);
        winAttr.colormap = cmColorMap;
        winAttr.border_pixel = 0;
        winAttr.event_mask = ExposureMask | StructureNotifyMask |
KeyPressMask | KeyReleaseMask;

 Atom wmDelete;
                // Create window
                win = XCreateWindow(dpDisplay, RootWindow(dpDisplay,
xvVisualInfo->screen),
                                                        0, 0,
                                                        ScreenWidth,
ScreenHeight, // Width and Height
                                                        0,
                                                        xvVisualInfo->depth,
// Depth
                                                        InputOutput,
                                                       
xvVisualInfo->visual,
                                                        CWBorderPixel |
CWColormap | CWEventMask,
                                                        &winAttr);
                if(!win)
                  {
                    return 0;
                  }
        wmDelete = XInternAtom(dpDisplay, "WM_DELETE_WINDOW", True);
                XSetWMProtocols(dpDisplay, win, &wmDelete, 1);
        XSetStandardProperties(dpDisplay, win, WindowTitle,WindowTitle,
None, NULL, 0, NULL);
        XMapRaised(dpDisplay, win);

 // Make it current
        glXMakeCurrent(dpDisplay, win, glXContext);

        // Map window on the display
        XMapWindow(dpDisplay, win);

        //SUCCESS!!!
        return true;

-- 
+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
NEU: Mit GMX ins Internet. GŁnstige DSL- & Modem/ISDN-Tarife!