1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2004 VideoLAN
7 * Authors: Cyril Deguet <asmax@videolan.org>
8 * code from projectM http://xmms-projectm.sourceforge.net
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.
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.
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 *****************************************************************************/
27 //video_init.c - SDL/Opengl Windowing Creation/Resizing Functions
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
37 #include "video_init.h"
42 void setup_opengl( int w, int h )
45 /* Our shading model--Gouraud (smooth). */
46 glShadeModel( GL_SMOOTH);
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 );
56 * Change to the projection matrix and set
59 glMatrixMode(GL_TEXTURE);
62 // gluOrtho2D(0.0, (GLfloat) width, 0.0, (GLfloat) height);
63 glMatrixMode(GL_PROJECTION);
66 // glFrustum(0.0, height, 0.0,width,10,40);
67 glMatrixMode(GL_MODELVIEW);
70 glDrawBuffer(GL_BACK);
71 glReadBuffer(GL_BACK);
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);
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);
88 void CreateRenderTarget(int texsize,int *RenderTargetTextureID, int *RenderTarget )
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);
96 /* Create the render target */
97 *RenderTarget = SDL_GL_CreateRenderTarget(texsize,texsize, NULL);
98 if ( *RenderTarget ) {
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 );
114 SDL_GL_BindRenderTarget(*RenderTarget, *RenderTargetTextureID);
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.
122 glBindTexture(GL_TEXTURE_2D, *RenderTargetTextureID);
123 glTexImage2D(GL_TEXTURE_2D,