On 04/06/2011 02:03 PM, DRC wrote:
A test program would be great. As far as KDE, modifying the source may
be simple, but building it is far from simple or quick. I have only a
limited amount of time to donate to unsponsored projects, so I have to
use it wisely.
You can use the attached program. It creates a 128x128 32-bit pixmap,
modifies it every frame and uses it as a texture through
EXT_texture_from_pixmap. Any pressed key closes the application.
When compiling, use g++ and link against X11, Xext, GL and GLU.
#include <X11/Xlib.h>
#include <X11/extensions/XShm.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <iostream>
#include <string>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glx.h>
#include <GL/glxext.h>
#include <math.h>
using namespace std;
Display* dpy;
Window w;
Pixmap p;
GC gc;
GLXContext context;
PFNGLXBINDTEXIMAGEEXTPROC binder;
PFNGLXRELEASETEXIMAGEEXTPROC unbinder;
int config_attrs[] = {
GLX_DOUBLEBUFFER, True,
GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
GLX_ALPHA_SIZE, 8,
GLX_DEPTH_SIZE, 24,
GLX_RENDER_TYPE, GLX_RGBA_BIT,
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT | GLX_PIXMAP_BIT,
GLX_X_RENDERABLE, True,
GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR,
None
};
int px_attrs[] = {
GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGBA_EXT,
GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
None
};
int main( int argc, char** argv )
{
dpy = XOpenDisplay( argv[ 1 ] );
if( dpy == NULL )
{
cout << "Failed to open display." << endl;
return -1;
}
Drawable sc = RootWindow( dpy, DefaultScreen( dpy ) );
GLXFBConfig config = 0;
int count = 0;
GLXFBConfig* configs = glXChooseFBConfig( dpy, DefaultScreen( dpy ), config_attrs, &count );
for( int i = 0; i < count; i ++ )
{
int value = 0;
glXGetFBConfigAttrib( dpy, configs[ i ], GLX_BIND_TO_TEXTURE_RGBA_EXT, &value );
if( value == 0 )
continue;
XVisualInfo* inf = glXGetVisualFromFBConfig( dpy, configs[ i ] );
if( inf == NULL )
continue;
XFree( inf );
config = configs[ i ];
if( config != 0 )
break;
}
if( config == 0 )
cout << "Failed to choose a correct FB config!" << endl;
else
cout << "FB config chosen." << endl;
XVisualInfo* vi = glXGetVisualFromFBConfig( dpy, config );
cout << "Visual depth: " << vi->depth << endl;
context = glXCreateNewContext( dpy, config, GLX_RGBA_TYPE, NULL, True );
if( context == 0 )
cout << "Failed to create GLX context!" << endl;
else
cout << "Context created." << endl;
Colormap cm = XCreateColormap( dpy, sc, vi->visual, AllocNone );
if( cm != 0 )
cout << "Colormap created." << endl;
XSetWindowAttributes wa;
wa.colormap = cm;
wa.event_mask = ExposureMask | ButtonPressMask | StructureNotifyMask | KeyPressMask;
XGCValues gcv;
p = XCreatePixmap( dpy, sc, 128, 128, 32 );
cout << "Pixmap created." << endl;
gc = XCreateGC( dpy, p, 0, &gcv );
w = XCreateWindow
( dpy, sc, 0, 0, 400, 400, 0, vi->depth, InputOutput, vi->visual,
CWColormap | CWEventMask, &wa );
cout << "Window created." << endl;
XSync( dpy, False );
XFree( vi );
glXMakeCurrent( dpy, w, context );
cout << "Context made current." << endl;
XMapWindow( dpy, w );
cout << "Window mapped." << endl;
GLuint tex_id = 0;
glEnable( GL_TEXTURE_2D );
glGenTextures( 1, & tex_id );
glBindTexture( GL_TEXTURE_2D, tex_id );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
unsigned char image[ 128 * 128 * 4 ];
for( int i = 0; i < 128 * 128 * 4; i ++ )
image[ i ] = ( i % 4 == 1 ) || ( i % 4 == 3 ) ? 255 : 0;
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, image );
cout << "Texture filled." << endl;
cout << "Config " << config << " pixmap " << p << endl;
GLXPixmap gl_p = glXCreatePixmap( dpy, config, p, px_attrs );
cout << "GLX Pixmap created." << endl;
const unsigned char* addr1 = ( const unsigned char* )( "glXBindTexImageEXT" );
const unsigned char* addr2 = ( const unsigned char* )( "glXReleaseTexImageEXT" );
binder = ( PFNGLXBINDTEXIMAGEEXTPROC )glXGetProcAddress( addr1 );
unbinder = ( PFNGLXRELEASETEXIMAGEEXTPROC )glXGetProcAddress( addr2 );
if( binder == 0 )
cout << "Binder not found" << endl;
else if( unbinder == 0 )
cout << "UnBinder not found" << endl;
else
cout << "Binders ready" << endl;
XSync( dpy, False );
XEvent event;
bool stop = false;
double angle = 0.0;
int x = 10;
int y = 10;
int dx = 1;
int dy = 0;
int width = 16;
int height = 16;
double counter = 0.0;
while( true )
{
if( XPending( dpy ) )
{
XNextEvent( dpy, &event );
switch( event.type )
{
case ConfigureNotify :
glViewport( 0, 0, event.xconfigure.width, event.xconfigure.height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 90, 1, 0.1, 1024 );
gluLookAt( 0, 0, -2, 0, 0, 0, 0, 1, 0 );
glMatrixMode( GL_MODELVIEW );
break;
case KeyPress:
stop = true;
break;
};
}
if( stop )
break;
unsigned long clear_color = 0xFFCCCCCC;
unsigned long fill_color0 = 0xFF00FF00;
unsigned long fill_color1 = 0xFFFF0000;
unsigned long fill_color2 = 0xFF0000FF;
unsigned long fill_color3 = 0xFF000000;
XSetForeground( dpy, gc, clear_color );
XFillRectangle( dpy, p, gc, 0, 0, 128, 128 );
XSetForeground( dpy, gc, fill_color0 );
XFillRectangle( dpy, p, gc, x, y, width, height );
XSetForeground( dpy, gc, fill_color1 );
XFillRectangle( dpy, p, gc, 112 - x, 112 - y, width, height );
XSetForeground( dpy, gc, fill_color2 );
XFillRectangle( dpy, p, gc, 112 - y, x, width, height );
XSetForeground( dpy, gc, fill_color3 );
XFillRectangle( dpy, p, gc, y, 112 - x, width, height );
XSync( dpy, False );
binder( dpy, gl_p, GLX_FRONT_LEFT_EXT, NULL );
glClear( GL_COLOR_BUFFER_BIT );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glRotated( angle, 0, 1, 0 );
glScaled( 0.5, 0.5, 0.5 );
glColor3d( 1, 0, 0 );
glBegin( GL_QUADS );
glTexCoord2d( 0, 0 );
glVertex3d( -1, -1, 0 );
glTexCoord2d( 0, 1 );
glVertex3d( -1, 1, 0 );
glTexCoord2d( 1, 1 );
glVertex3d( 1, 1, 0 );
glTexCoord2d( 1, 0 );
glVertex3d( 1, -1, 0 );
glEnd();
unbinder( dpy, gl_p, GLX_FRONT_LEFT_EXT );
glXSwapBuffers( dpy, w );
angle += 0.01;
counter += 0.1;
x += dx * static_cast< int >( counter );
y += dy * static_cast< int >( counter );
if( counter > 1.0 )
counter = 0.0;
if( x == 102 && dx == 1 )
{
dx = 0;
dy = 1;
}
else if( y == 102 && dy == 1 )
{
dx = -1;
dy = 0;
}
else if( x == 10 && dx == -1 )
{
dx = 0;
dy = -1;
}
else if( y == 10 && dy == -1 )
{
dx = 1;
dy = 0;
}
}
XUnmapWindow( dpy, w );
XFreeGC( dpy, gc );
XDestroyWindow( dpy, w );
XCloseDisplay( dpy );
return 0;
}
------------------------------------------------------------------------------
Xperia(TM) PLAY
It's a major breakthrough. An authentic gaming
smartphone on the nation's most reliable network.
And it wants your games.
http://p.sf.net/sfu/verizon-sfdev
_______________________________________________
VirtualGL-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/virtualgl-users