]> git.sesse.net Git - vlc/blob - modules/visualization/galaktos/video_init.c
Merge branch 1.0-bugfix
[vlc] / modules / visualization / galaktos / video_init.c
1 /*****************************************************************************
2  * video_init.c:
3  *****************************************************************************
4  * Copyright (C) 2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Cyril Deguet <asmax@videolan.org>
8  *          code from projectM http://xmms-projectm.sourceforge.net
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25
26
27 //video_init.c - SDL/Opengl Windowing Creation/Resizing Functions
28 //
29 //by Peter Sperl
30 //
31 //Opens an SDL Window and creates an OpenGL session
32 //also able to handle resizing and fullscreening of windows
33 //just call init_display again with differant variables
34
35 #include <stdlib.h>
36 #include <GL/gl.h>
37 #include <GL/glu.h>
38 #include "video_init.h"
39
40 extern int texsize;
41
42 extern char *buffer;
43
44
45 void setup_opengl( int w, int h )
46 {
47    
48     /* Our shading model--Gouraud (smooth). */
49      glShadeModel( GL_SMOOTH);
50     /* Culling. */
51     //    glCullFace( GL_BACK );
52     //    glFrontFace( GL_CCW );
53     //    glEnable( GL_CULL_FACE );
54     /* Set the clear color. */
55     glClearColor( 0, 0, 0, 0 );
56     /* Setup our viewport. */
57      glViewport( 0, 0, w, h );
58     /*
59      * Change to the projection matrix and set
60      * our viewing volume.
61      */
62     glMatrixMode(GL_TEXTURE);
63     glLoadIdentity();
64     
65     //    gluOrtho2D(0.0, (GLfloat) width, 0.0, (GLfloat) height);
66     glMatrixMode(GL_PROJECTION);
67     glLoadIdentity();  
68    
69     //    glFrustum(0.0, height, 0.0,width,10,40);
70     glMatrixMode(GL_MODELVIEW);
71     glLoadIdentity();
72
73 glDrawBuffer(GL_BACK); 
74   glReadBuffer(GL_BACK); 
75   glEnable(GL_BLEND); 
76
77      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
78      // glBlendFunc(GL_SRC_ALPHA, GL_ONE); 
79   glEnable(GL_LINE_SMOOTH);
80   glEnable(GL_POINT_SMOOTH);
81   glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
82   glClear(GL_COLOR_BUFFER_BIT);
83  
84   // glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGB,0,0,texsize,texsize,0);
85   //glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,texsize,texsize);
86    glLineStipple(2, 0xAAAA);
87   
88     
89 }
90
91 void CreateRenderTarget(int texsize,int *RenderTargetTextureID, int *RenderTarget )
92 {
93     /* Create the texture that will be bound to the render target */
94     glGenTextures(1, RenderTargetTextureID);
95     glBindTexture(GL_TEXTURE_2D, *RenderTargetTextureID);
96     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
97     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
98 #if 0
99     /* Create the render target */
100     *RenderTarget = SDL_GL_CreateRenderTarget(texsize,texsize, NULL);
101         if ( *RenderTarget ) {
102     
103         int value;
104
105         //printf("Created render target:\n");
106         SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_RED_SIZE, &value );
107         //      printf( "SDL_GL_RED_SIZE: %d\n", value);
108         SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_GREEN_SIZE, &value );
109         //      printf( "SDL_GL_GREEN_SIZE: %d\n", value);
110         SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_BLUE_SIZE, &value );
111         //      printf( "SDL_GL_BLUE_SIZE: %d\n", value);
112         SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_ALPHA_SIZE, &value );
113         //      printf( "SDL_GL_ALPHA_SIZE: %d\n", value);
114         SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_DEPTH_SIZE, &value );
115         //      printf( "SDL_GL_DEPTH_SIZE: %d\n", value );
116
117         SDL_GL_BindRenderTarget(*RenderTarget, *RenderTargetTextureID);
118        
119     } else {
120 #endif
121         /* We can fake a render target in this demo by rendering to the
122          * screen and copying to a texture before we do normal rendering.
123          */
124     buffer = malloc(3*texsize*texsize);
125
126         glBindTexture(GL_TEXTURE_2D, *RenderTargetTextureID);
127         glTexImage2D(GL_TEXTURE_2D,
128                         0,
129                         GL_RGB,
130                         texsize, texsize,
131                         0,
132                         GL_RGB,
133                         GL_UNSIGNED_BYTE,
134                         buffer);
135  //   }
136
137 }
138
139
140
141