1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2004 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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"
44 void setup_opengl( int w, int h )
47 /* Our shading model--Gouraud (smooth). */
48 glShadeModel( GL_SMOOTH);
50 // glCullFace( GL_BACK );
51 // glFrontFace( GL_CCW );
52 // glEnable( GL_CULL_FACE );
53 /* Set the clear color. */
54 glClearColor( 0, 0, 0, 0 );
55 /* Setup our viewport. */
56 glViewport( 0, 0, w, h );
58 * Change to the projection matrix and set
61 glMatrixMode(GL_TEXTURE);
64 // gluOrtho2D(0.0, (GLfloat) width, 0.0, (GLfloat) height);
65 glMatrixMode(GL_PROJECTION);
68 // glFrustum(0.0, height, 0.0,width,10,40);
69 glMatrixMode(GL_MODELVIEW);
72 glDrawBuffer(GL_BACK);
73 glReadBuffer(GL_BACK);
76 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
77 // glBlendFunc(GL_SRC_ALPHA, GL_ONE);
78 glEnable(GL_LINE_SMOOTH);
79 glEnable(GL_POINT_SMOOTH);
80 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
81 glClear(GL_COLOR_BUFFER_BIT);
83 // glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGB,0,0,texsize,texsize,0);
84 //glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,texsize,texsize);
85 glLineStipple(2, 0xAAAA);
90 void CreateRenderTarget(int texsize,int *RenderTargetTextureID, int *RenderTarget )
92 /* Create the texture that will be bound to the render target */
93 glGenTextures(1, RenderTargetTextureID);
94 glBindTexture(GL_TEXTURE_2D, *RenderTargetTextureID);
95 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
96 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
98 /* Create the render target */
99 *RenderTarget = SDL_GL_CreateRenderTarget(texsize,texsize, NULL);
100 if ( *RenderTarget ) {
104 //printf("Created render target:\n");
105 SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_RED_SIZE, &value );
106 // printf( "SDL_GL_RED_SIZE: %d\n", value);
107 SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_GREEN_SIZE, &value );
108 // printf( "SDL_GL_GREEN_SIZE: %d\n", value);
109 SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_BLUE_SIZE, &value );
110 // printf( "SDL_GL_BLUE_SIZE: %d\n", value);
111 SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_ALPHA_SIZE, &value );
112 // printf( "SDL_GL_ALPHA_SIZE: %d\n", value);
113 SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_DEPTH_SIZE, &value );
114 // printf( "SDL_GL_DEPTH_SIZE: %d\n", value );
116 SDL_GL_BindRenderTarget(*RenderTarget, *RenderTargetTextureID);
120 /* We can fake a render target in this demo by rendering to the
121 * screen and copying to a texture before we do normal rendering.
123 buffer = malloc(3*texsize*texsize);
125 glBindTexture(GL_TEXTURE_2D, *RenderTargetTextureID);
126 glTexImage2D(GL_TEXTURE_2D,