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
38 #include "video_init.h"
45 void setup_opengl( int w, int h )
48 /* Our shading model--Gouraud (smooth). */
49 glShadeModel( GL_SMOOTH);
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 );
59 * Change to the projection matrix and set
62 glMatrixMode(GL_TEXTURE);
65 // gluOrtho2D(0.0, (GLfloat) width, 0.0, (GLfloat) height);
66 glMatrixMode(GL_PROJECTION);
69 // glFrustum(0.0, height, 0.0,width,10,40);
70 glMatrixMode(GL_MODELVIEW);
73 glDrawBuffer(GL_BACK);
74 glReadBuffer(GL_BACK);
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);
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);
91 void CreateRenderTarget(int texsize,int *RenderTargetTextureID, int *RenderTarget )
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);
99 /* Create the render target */
100 *RenderTarget = SDL_GL_CreateRenderTarget(texsize,texsize, NULL);
101 if ( *RenderTarget ) {
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 );
117 SDL_GL_BindRenderTarget(*RenderTarget, *RenderTargetTextureID);
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.
124 buffer = malloc(3*texsize*texsize);
126 glBindTexture(GL_TEXTURE_2D, *RenderTargetTextureID);
127 glTexImage2D(GL_TEXTURE_2D,