]> git.sesse.net Git - vlc/blob - modules/visualization/galaktos/video_init.c
* all: first implementation of a MilkDrop-compatible visualization plugin,
[vlc] / modules / visualization / galaktos / video_init.c
1 /*****************************************************************************
2  * video_init.c:
3  *****************************************************************************
4  * Copyright (C) 2004 VideoLAN
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., 59 Temple Place - Suite 330, Boston, MA  02111, 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 <GL/gl.h>
36 #include <GL/glu.h>
37 #include "video_init.h"
38
39 extern int texsize;
40
41
42 void setup_opengl( int w, int h )
43 {
44    
45     /* Our shading model--Gouraud (smooth). */
46      glShadeModel( GL_SMOOTH);
47     /* Culling. */
48     //    glCullFace( GL_BACK );
49     //    glFrontFace( GL_CCW );
50     //    glEnable( GL_CULL_FACE );
51     /* Set the clear color. */
52     glClearColor( 0, 0, 0, 0 );
53     /* Setup our viewport. */
54      glViewport( 0, 0, w, h );
55     /*
56      * Change to the projection matrix and set
57      * our viewing volume.
58      */
59     glMatrixMode(GL_TEXTURE);
60     glLoadIdentity();
61     
62     //    gluOrtho2D(0.0, (GLfloat) width, 0.0, (GLfloat) height);
63     glMatrixMode(GL_PROJECTION);
64     glLoadIdentity();  
65    
66     //    glFrustum(0.0, height, 0.0,width,10,40);
67     glMatrixMode(GL_MODELVIEW);
68     glLoadIdentity();
69
70 glDrawBuffer(GL_BACK); 
71   glReadBuffer(GL_BACK); 
72   glEnable(GL_BLEND); 
73
74      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
75      // glBlendFunc(GL_SRC_ALPHA, GL_ONE); 
76   glEnable(GL_LINE_SMOOTH);
77   glEnable(GL_POINT_SMOOTH);
78   glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
79   glClear(GL_COLOR_BUFFER_BIT);
80  
81   // glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGB,0,0,texsize,texsize,0);
82   //glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,texsize,texsize);
83    glLineStipple(2, 0xAAAA);
84   
85     
86 }
87
88 void CreateRenderTarget(int texsize,int *RenderTargetTextureID, int *RenderTarget )
89 {
90     /* Create the texture that will be bound to the render target */
91     glGenTextures(1, RenderTargetTextureID);
92     glBindTexture(GL_TEXTURE_2D, *RenderTargetTextureID);
93     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
94     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
95 #if 0
96     /* Create the render target */
97     *RenderTarget = SDL_GL_CreateRenderTarget(texsize,texsize, NULL);
98         if ( *RenderTarget ) {
99     
100         int value;
101
102         //printf("Created render target:\n");
103         SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_RED_SIZE, &value );
104         //      printf( "SDL_GL_RED_SIZE: %d\n", value);
105         SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_GREEN_SIZE, &value );
106         //      printf( "SDL_GL_GREEN_SIZE: %d\n", value);
107         SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_BLUE_SIZE, &value );
108         //      printf( "SDL_GL_BLUE_SIZE: %d\n", value);
109         SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_ALPHA_SIZE, &value );
110         //      printf( "SDL_GL_ALPHA_SIZE: %d\n", value);
111         SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_DEPTH_SIZE, &value );
112         //      printf( "SDL_GL_DEPTH_SIZE: %d\n", value );
113
114         SDL_GL_BindRenderTarget(*RenderTarget, *RenderTargetTextureID);
115        
116     } else {
117 #endif
118         /* We can fake a render target in this demo by rendering to the
119          * screen and copying to a texture before we do normal rendering.
120          */
121
122         glBindTexture(GL_TEXTURE_2D, *RenderTargetTextureID);
123         glTexImage2D(GL_TEXTURE_2D,
124                         0,
125                         GL_RGB,
126                         texsize, texsize,
127                         0,
128                         GL_RGB,
129                         GL_UNSIGNED_BYTE,
130                         0);
131  //   }
132
133 }
134
135
136
137