Commits

Ivan Vučica  committed 23cba1b

Managed to get the image by using glReadPixels() and gluBuild2DMipmaps(). Of course, this is hideously slow.

  • Participants
  • Parent commits 2c717ce

Comments (0)

Files changed (2)

File FPManagedWindow.m

 #import <X11/extensions/shape.h>
 #import <X11/extensions/Xdamage.h>
 #import <GL/gl.h>
+#import <GL/glu.h>
 #import <GL/glx.h>
-#import <GL/glext.h>
+#import <GL/glxext.h>
 #import "FPX11Display.h"
 #import "FPManagedWindow.h"
 #import "FPEventLoop.h"
 #import "FPWindowManager.h"
 
 static int DamageNotify = -1;
+static PFNGLXBINDTEXIMAGEEXTPROC glXBindTexImageEXT = 0;
 @implementation FPManagedWindow
 
 -(id)initWithWindow:(Window)window manager:(FPWindowManager*)manager
 		if(event.xexpose.window == _window)
 		{
 			NSLog(@"Managed Window %ld is exposed", _window);
+			if(glXBindTexImageEXT == 0)
+			{
+				// TODO: initialize once, globally
+				glXBindTexImageEXT = (PFNGLXBINDTEXIMAGEEXTPROC)glXGetProcAddress((GLubyte*)"glXBindTexImageEXT");
+			}
 		}
 		break;
 
 		for (list = mirror->draw_zone; list; list = g_slist_next (list))
 			quad_draw (list->data);
 		*/
-		glTexCoord2f(0,0); glVertex3f(0,0,0);
-		glTexCoord2f(0,1); glVertex3f(0,_height,0);
-		glTexCoord2f(1,1); glVertex3f(_width, _height, 0);
-		glTexCoord2f(1,0); glVertex3f(_width, 0, 0);
+
+		#define INVERTED_Y 1
+		#if INVERTED_Y
+		#define _Y(y) 1-y
+		#else
+		#define _Y(y) y
+		#endif
+
+		glTexCoord2f(0,_Y(0)); glVertex3f(0,0,0);
+		glTexCoord2f(0,_Y(1)); glVertex3f(0,_height,0);
+		glTexCoord2f(1,_Y(1)); glVertex3f(_width, _height, 0);
+		glTexCoord2f(1,_Y(0)); glVertex3f(_width, 0, 0);
+		
+		#undef _Y
 		
 		glEnd();
 		/*
 		extent_unclip ();
 		*/
-		
+
+		glLineWidth(4);		
 		glDisable(_textureTarget);
 		glColor4f(0,0,0,1);
 		glBegin(GL_LINE_LOOP);
 		glEnd();
 		glColor4f(1,1,1,1);
 		glEnable(_textureTarget);
-
+		glLineWidth(1);
 
 	glPopMatrix ();
 	glDisable(_textureTarget);
 	}
 */
 	glXWaitX();
+	glXWaitGL();
+	
 
-	glXQueryDrawable(display, _drawable, GLX_TEXTURE_TARGET_EXT, &_textureTarget);
+	_textureTarget = GLX_TEXTURE_2D_EXT; //glXQueryDrawable(display, _drawable, GLX_TEXTURE_TARGET_EXT, &_textureTarget);
 	switch(_textureTarget)
 	{
 		case GLX_TEXTURE_2D_EXT:
 	glEnable(_textureTarget);
 	if(!_texture)
 		glGenTextures (1, &_texture);
-	glBindTexture(_textureTarget, _texture);
 
-	// FIXME: couldn't get this to compile:
-	//glXBindTexImageEXT(display, _drawable, GLX_FRONT_LEFT_EXT, NULL);
+	if(glXBindTexImageEXT)
+		glXBindTexImageEXT(display, _drawable, GLX_FRONT_LEFT_EXT, NULL);
+	else
+	{
+		glBindTexture(_textureTarget, _texture);
 
-	// FIXME: we don't actually get any image for some reason
-	// NOTE: using the damage extension we could just glCopyTexSubImage2D()
-	glCopyTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, 
-			0, 0, _width, _height, 0);
+#if HAVE_GL_COPY_TEX_IMAGE_2D
+		// FIXME: we don't actually get any image for some reason
+		// NOTE: using the damage extension we could just glCopyTexSubImage2D()
+		glCopyTexImage2D (_textureTarget, 0, GL_RGBA, 
+				0, 0, _width, _height, 0);
+#else
+		// FIXME: abysmally slow, and blurry, too
+		GLubyte * img = (GLubyte*)malloc(_width * _height * 4);
+		glReadPixels(0, 0, _width, _height, GL_RGBA, GL_UNSIGNED_BYTE, img);
 		
+		glXWaitX();
+		glXWaitGL();
+		gluBuild2DMipmaps(_textureTarget, GL_RGBA, _width, _height, GL_RGBA, GL_UNSIGNED_BYTE, img);
+		glXWaitGL();
+		glXWaitX();
+		free(img);
+#endif
+	}
+	
 	glDisable(GL_TEXTURE);
 	glDisable(_textureTarget);
 	

File FPWindowManager.m

         glXWaitVideoSync( 2, ( sync + 1 ) % 2, &sync );
 #endif
 	/* end vsync */
+}
 
+/*
+-(BOOL)_setupTexture
+{
+	int textureData[] = {
+		255, 0, 0,     255, 255, 255,
+		255, 255, 255, 0, 0, 0
+	};
+
+	GLuint _width = 2, _height = 2;
+	GLuint _internalFormat = GL_RGBA;
+        glGenTextures(1, &testTexture);
+
+        GLuint errorID=glGetError();
+        if(errorID != GL_NO_ERROR)
+        {
+                printf("GL ERROR: %d\n", (errorID));
+                return NO;
+        }
+        glBindTexture(GL_TEXTURE_2D, testTexture);
+        glTexImage2D(GL_TEXTURE_2D, 0, _internalFormat, (GLsizei)_width, (GLsizei)_height, 0, _internalFormat, GL_UNSIGNED_BYTE, textureData);
+        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+	return YES;	
 }
+*/
+
 -(void)updateWithDeltaTime:(float)sec;
 {