Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

video_init.c

00001 /*****************************************************************************
00002  * video_init.c:
00003  *****************************************************************************
00004  * Copyright (C) 2004 the VideoLAN team
00005  * $Id: video_init.c 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Cyril Deguet <[email protected]>
00008  *          code from projectM http://xmms-projectm.sourceforge.net
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 
00026 
00027 //video_init.c - SDL/Opengl Windowing Creation/Resizing Functions
00028 //
00029 //by Peter Sperl
00030 //
00031 //Opens an SDL Window and creates an OpenGL session
00032 //also able to handle resizing and fullscreening of windows
00033 //just call init_display again with differant variables
00034 
00035 #include <GL/gl.h>
00036 #include <GL/glu.h>
00037 #include "video_init.h"
00038 
00039 extern int texsize;
00040 
00041 extern char *buffer;
00042 
00043 
00044 void setup_opengl( int w, int h )
00045 {
00046    
00047     /* Our shading model--Gouraud (smooth). */
00048      glShadeModel( GL_SMOOTH);
00049     /* Culling. */
00050     //    glCullFace( GL_BACK );
00051     //    glFrontFace( GL_CCW );
00052     //    glEnable( GL_CULL_FACE );
00053     /* Set the clear color. */
00054     glClearColor( 0, 0, 0, 0 );
00055     /* Setup our viewport. */
00056      glViewport( 0, 0, w, h );
00057     /*
00058      * Change to the projection matrix and set
00059      * our viewing volume.
00060      */
00061     glMatrixMode(GL_TEXTURE);
00062     glLoadIdentity();
00063     
00064     //    gluOrtho2D(0.0, (GLfloat) width, 0.0, (GLfloat) height);
00065     glMatrixMode(GL_PROJECTION);
00066     glLoadIdentity();  
00067    
00068     //    glFrustum(0.0, height, 0.0,width,10,40);
00069     glMatrixMode(GL_MODELVIEW);
00070     glLoadIdentity();
00071 
00072 glDrawBuffer(GL_BACK); 
00073   glReadBuffer(GL_BACK); 
00074   glEnable(GL_BLEND); 
00075 
00076      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
00077      // glBlendFunc(GL_SRC_ALPHA, GL_ONE); 
00078   glEnable(GL_LINE_SMOOTH);
00079   glEnable(GL_POINT_SMOOTH);
00080   glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
00081   glClear(GL_COLOR_BUFFER_BIT);
00082  
00083   // glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGB,0,0,texsize,texsize,0);
00084   //glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,texsize,texsize);
00085    glLineStipple(2, 0xAAAA);
00086   
00087     
00088 }
00089 
00090 void CreateRenderTarget(int texsize,int *RenderTargetTextureID, int *RenderTarget )
00091 {
00092     /* Create the texture that will be bound to the render target */
00093     glGenTextures(1, RenderTargetTextureID);
00094     glBindTexture(GL_TEXTURE_2D, *RenderTargetTextureID);
00095     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00096     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00097 #if 0
00098     /* Create the render target */
00099     *RenderTarget = SDL_GL_CreateRenderTarget(texsize,texsize, NULL);
00100         if ( *RenderTarget ) {
00101     
00102         int value;
00103 
00104         //printf("Created render target:\n");
00105         SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_RED_SIZE, &value );
00106         //      printf( "SDL_GL_RED_SIZE: %d\n", value);
00107         SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_GREEN_SIZE, &value );
00108         //      printf( "SDL_GL_GREEN_SIZE: %d\n", value);
00109         SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_BLUE_SIZE, &value );
00110         //      printf( "SDL_GL_BLUE_SIZE: %d\n", value);
00111         SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_ALPHA_SIZE, &value );
00112         //      printf( "SDL_GL_ALPHA_SIZE: %d\n", value);
00113         SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_DEPTH_SIZE, &value );
00114         //      printf( "SDL_GL_DEPTH_SIZE: %d\n", value );
00115 
00116         SDL_GL_BindRenderTarget(*RenderTarget, *RenderTargetTextureID);
00117        
00118     } else {
00119 #endif
00120         /* We can fake a render target in this demo by rendering to the
00121          * screen and copying to a texture before we do normal rendering.
00122          */
00123     buffer = malloc(3*texsize*texsize);
00124 
00125         glBindTexture(GL_TEXTURE_2D, *RenderTargetTextureID);
00126         glTexImage2D(GL_TEXTURE_2D,
00127                         0,
00128                         GL_RGB,
00129                         texsize, texsize,
00130                         0,
00131                         GL_RGB,
00132                         GL_UNSIGNED_BYTE,
00133                         buffer);
00134  //   }
00135 
00136 }
00137 
00138 
00139 
00140 

Generated on Tue Dec 20 10:14:59 2005 for vlc-0.8.4a by  doxygen 1.4.2