From: Gernot Z. <ma...@us...> - 2003-10-27 22:12:20
|
CVS Root: /cvsroot/gstreamer Module: gst-plugins Changes by: madmac Date: Mon Oct 27 2003 14:07:27 PST Branch: BRANCH-GSTREAMER-0_6 Log message: improvements to glsink demo mode and autodetection Modified files: sys/glsink : gstgl_nvimage.c gstgl_rgbimage.c gstglsink.c gstglxwindow.c Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins/sys/glsink/gstgl_nvimage.c.diff?r1=1.1.2.2&r2=1.1.2.3 http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins/sys/glsink/gstgl_rgbimage.c.diff?r1=1.1.2.2&r2=1.1.2.3 http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins/sys/glsink/gstglsink.c.diff?r1=1.1.2.2&r2=1.1.2.3 http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins/sys/glsink/gstglxwindow.c.diff?r1=1.1.2.2&r2=1.1.2.3 ====Begin Diffs==== Index: gstgl_nvimage.c =================================================================== RCS file: /cvsroot/gstreamer/gst-plugins/sys/glsink/Attic/gstgl_nvimage.c,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -d -r1.1.2.2 -r1.1.2.3 --- gstgl_nvimage.c 27 Oct 2003 18:34:48 -0000 1.1.2.2 +++ gstgl_nvimage.c 27 Oct 2003 22:07:15 -0000 1.1.2.3 @@ -21,6 +21,7 @@ //#include <GL/glext.h> #include <GL/glu.h> #include <string.h> +#include <math.h> // too lazy to write an API for this ;) #include "regcomb_yuvrgb.c" @@ -243,26 +244,26 @@ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glTranslatef(0.0, 0.0, -50.0); + glTranslatef(0.0, 0.0, -25.0); glEnable(GL_TEXTURE_2D); - glPushMatrix(); - //glTranslatef(0,1,0); - glRotatef(xinfo->rotX,1,0,0); - glRotatef(xinfo->rotY,0,1,0); - if (xinfo->info.demo) { - //xinfo->rotX += 0.2; - //xinfo->rotY -= 0.2; + + glRotatef(180.0*sin(xinfo->rotX),1,0,0); + glRotatef(180.0*cos(xinfo->rotY),0,1,0); + + xinfo->rotX += 0.01; + xinfo->rotY -= 0.015; float zoom = xinfo->zoom; glScalef(zoom,zoom,zoom); - - if (xinfo->zoom > 2.0) - xinfo->zoomdir = -0.05; + //glScalef(0.1,0.1,0.1); - if (xinfo->zoom < 1.0) - xinfo->zoomdir = 0.05; + if (xinfo->zoom > 1.0) + xinfo->zoomdir = -0.01; + + if (xinfo->zoom < 0.5) + xinfo->zoomdir = 0.01; xinfo->zoom += xinfo->zoomdir; } @@ -285,31 +286,32 @@ //glColor4f(1,1,1,1); // do NOT set a color here ! Done by Initialize_Backend, or actually SetConst ! glBegin(GL_QUADS); + float aspect = img_width/(float)img_height; + float hor = 4 * aspect; + glNormal3f(0, -1, 0); glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0,0); glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0,0); glMultiTexCoord2fARB(GL_TEXTURE2_ARB,0,0); - glVertex3f(-4,4,0); + glVertex3f(-hor,4,0); glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0,ymax); glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0,ymax); glMultiTexCoord2fARB(GL_TEXTURE2_ARB,0,ymax); - glVertex3f(-4,-4,0); + glVertex3f(-hor,-4,0); glMultiTexCoord2fARB(GL_TEXTURE0_ARB,xmax,ymax); glMultiTexCoord2fARB(GL_TEXTURE1_ARB,xmax,ymax); glMultiTexCoord2fARB(GL_TEXTURE2_ARB,xmax,ymax); - glVertex3f(4,-4,0); + glVertex3f(hor,-4,0); glMultiTexCoord2fARB(GL_TEXTURE0_ARB,xmax,0); glMultiTexCoord2fARB(GL_TEXTURE1_ARB,xmax,0); glMultiTexCoord2fARB(GL_TEXTURE2_ARB,xmax,0); - glVertex3f(4,4,0); + glVertex3f(hor,4,0); glEnd(); - glPopMatrix(); - if (xinfo->info.dumpvideo) { static int framenr = 0; @@ -371,7 +373,7 @@ GstGLImageInfo *xinfo = gst_gl_nvimage_info (info); GstGLImageConnection *xconn = gst_gl_nvimage_connection (conn); - g_warning("Opening NVidia GL context connection, using register combiners.\n"); + g_print("Opening NVidia connection; OpenGL on Nvidia, using register combiners.\n"); { Ywidth = TEX_XSIZE; Yheight = TEX_YSIZE; UVwidth = TEX_XSIZE/2; UVheight = TEX_YSIZE/2; Initialize_Backend(Ywidth,Yheight,UVwidth,UVheight,GL_LINEAR); Index: gstgl_rgbimage.c =================================================================== RCS file: /cvsroot/gstreamer/gst-plugins/sys/glsink/Attic/gstgl_rgbimage.c,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -d -r1.1.2.2 -r1.1.2.3 --- gstgl_rgbimage.c 27 Oct 2003 18:34:48 -0000 1.1.2.2 +++ gstgl_rgbimage.c 27 Oct 2003 22:07:15 -0000 1.1.2.3 @@ -17,6 +17,7 @@ #include <GL/glx.h> #include <GL/gl.h> #include <GL/glu.h> +#include <math.h> #include "gstglsink.h" @@ -231,52 +232,102 @@ GstGLImageInfo *xinfo = gst_gl_rgbimage_info (info); GstGLImage *im = (GstGLImage *) image; + int img_width = im->conn->w; + int img_height = im->conn->h; + g_assert (xinfo != NULL); - g_warning("PUTTING IMAGE"); // both upload the video, and redraw the screen glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glTranslatef(0.0, 0.0, -50.0); + glTranslatef(0.0, 0.0, -25.0); glEnable(GL_TEXTURE_2D); - glPushMatrix(); - //glTranslatef(0,1,0); - glRotatef(xinfo->rotX-250,1,0,0); - glRotatef(xinfo->rotY,0,1,0); - int zoom = xinfo->zoom; - glScaled(zoom,zoom,zoom); - //Draws the surface rectangle + if (xinfo->info.demo) + { + + glRotatef(180.0*sin(xinfo->rotX),1,0,0); + glRotatef(180.0*cos(xinfo->rotY),0,1,0); + + xinfo->rotX += 0.01; + xinfo->rotY -= 0.015; + float zoom = xinfo->zoom; + glScalef(zoom,zoom,zoom); + //glScalef(0.1,0.1,0.1); + if (xinfo->zoom > 1.0) + xinfo->zoomdir = -0.01; + + if (xinfo->zoom < 0.5) + xinfo->zoomdir = 0.01; + + xinfo->zoom += xinfo->zoomdir; + } + + //Draws the surface rectangle glBindTexture(GL_TEXTURE_2D, im->conn->rgbatex_id); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, im->conn->w, im->conn->h, GL_RGBA, GL_UNSIGNED_BYTE, im->data.data); xmax = (float)im->conn->w/TEX_XSIZE; ymax = (float)im->conn->h/TEX_YSIZE; + float aspect = img_width/(float)img_height; + float hor = 4 * aspect; + glColor4f(1,1,1,1); glBegin(GL_QUADS); glNormal3f(0, -1, 0); glTexCoord2f(xmax, 0); - glVertex3f(4,4,0); + glVertex3f(hor,4,0); glTexCoord2f(0, 0); - glVertex3f(-4,4,0); + glVertex3f(-hor,4,0); glTexCoord2f(0, ymax); - glVertex3f(-4,-4,0); + glVertex3f(-hor,-4,0); glTexCoord2f(xmax, ymax); - glVertex3f(4,-4,0); - + glVertex3f(hor,-4,0); glEnd(); - glPopMatrix(); + if (xinfo->info.dumpvideo) + { + static int framenr = 0; + char capfilename[255]; + static guint8 *cap_image_data = NULL, *cap_image_data2 = NULL; + int i; + + // hmmmm, is this reentrant ?! + if (cap_image_data == NULL) + cap_image_data = (guint8 *)malloc(img_width * img_height * 3); + + if (cap_image_data2 == NULL) + cap_image_data2 = (guint8 *)malloc(img_width * img_height * 3); + + printf("Recording frame #%d\n", framenr); + glReadPixels(0,0,img_width,img_height,GL_RGB,GL_UNSIGNED_BYTE,cap_image_data); + // invert the pixels + for (i = 0; i < img_height; i++) + memcpy(cap_image_data2 + i * img_width * 3, cap_image_data + (img_height-1-i) * img_width * 3, img_width*3); + + sprintf(capfilename, "cap%04d.ppm", framenr); + FILE *outfile = fopen(capfilename, "wb"); + if (outfile != NULL) + { + fprintf(outfile, "P6\n"); + fprintf(outfile,"# created by raw_zb\n"); + fprintf(outfile,"%d %d\n",img_width,img_height); + fprintf(outfile,"255\n"); + fwrite(cap_image_data2, sizeof(char), img_width*img_height*3, outfile); + fclose(outfile); + } + framenr++; + } glXSwapBuffers(xinfo->dpy, xinfo->win); } @@ -295,7 +346,7 @@ static void gst_gl_rgbimage_open_conn (GstImageConnection *conn, GstImageInfo *info) { - g_warning("!!! Opening Connection !!!"); + g_warning("Opening RGB Connection; classic OpenGL 1.2 renderer."); GstGLImageInfo *xinfo = gst_gl_rgbimage_info (info); GstGLImageConnection *xconn = gst_gl_rgbimage_connection (conn); Index: gstglsink.c =================================================================== RCS file: /cvsroot/gstreamer/gst-plugins/sys/glsink/Attic/gstglsink.c,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -d -r1.1.2.2 -r1.1.2.3 --- gstglsink.c 27 Oct 2003 18:34:48 -0000 1.1.2.2 +++ gstglsink.c 27 Oct 2003 22:07:15 -0000 1.1.2.3 @@ -213,8 +213,7 @@ /* plugins */ klass->plugins = NULL; - //klass->plugins = g_list_append (klass->plugins, get_xvimage_plugin ()); - //klass->plugins = g_list_append (klass->plugins, get_gl_rgbimage_plugin ()); + klass->plugins = g_list_append (klass->plugins, get_gl_rgbimage_plugin ()); klass->plugins = g_list_append (klass->plugins, get_gl_nvimage_plugin ()); } Index: gstglxwindow.c =================================================================== RCS file: /cvsroot/gstreamer/gst-plugins/sys/glsink/Attic/gstglxwindow.c,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -d -r1.1.2.2 -r1.1.2.3 --- gstglxwindow.c 27 Oct 2003 18:34:48 -0000 1.1.2.2 +++ gstglxwindow.c 27 Oct 2003 22:07:15 -0000 1.1.2.3 @@ -147,14 +147,14 @@ if (vi == NULL) { vi = glXChooseVisual(new->dpy, new->screen, attrListSgl); - g_warning("Only Singlebuffered Visual!\n"); + GST_DEBUG(0,"Only Singlebuffered Visual!\n"); } else { - g_warning("Got Doublebuffered Visual!\n"); + GST_DEBUG(0,"Got Doublebuffered Visual!\n"); } glXQueryVersion(new->dpy, &glxMajorVersion, &glxMinorVersion); - g_warning("glX-Version %d.%d\n", glxMajorVersion, glxMinorVersion); + GST_DEBUG(0,"glX-Version %d.%d\n", glxMajorVersion, glxMinorVersion); /* create a GLX context */ new->ctx = glXCreateContext(new->dpy, vi, 0, GL_TRUE); @@ -172,7 +172,8 @@ new->rotX = 0; new->rotY = 0; - new->zoom = 2; + new->zoom = 1; + new->zoomdir = 0.01; { /* create a window in window mode*/ @@ -200,11 +201,11 @@ &new->width, &new->height, &borderDummy, &new->depth); printf("Depth %d\n", new->depth); if (glXIsDirect(new->dpy, new->ctx)) - g_warning("Congrats, you have Direct Rendering!\n"); + GST_DEBUG (GST_CAT_PLUGIN_INFO, "Congrats, you have Direct Rendering!\n"); else - g_warning("Sorry, no Direct Rendering possible!\n"); + GST_DEBUG (GST_CAT_PLUGIN_INFO, "Sorry, no Direct Rendering possible!\n"); - g_warning("Initializing OpenGL parameters"); + GST_DEBUG(GST_CAT_PLUGIN_INFO, "Initializing OpenGL parameters\n"); /* initialize OpenGL drawing */ glEnable(GL_DEPTH_TEST); //glShadeModel(GL_SMOOTH); |