/* =============== GLimp_EndFrame Responsible for doing a swapbuffers =============== */ void GLimp_EndFrame( void ) { #ifdef HAVE_GLES EGL_SwapBuffers(); #else // don't flip if drawing to front buffer if ( Q_stricmp( r_drawBuffer->string, "GL_FRONT" ) != 0 ) { SDL_GL_SwapBuffers(); } #endif if( r_fullscreen->modified ) { qboolean fullscreen; qboolean needToToggle = qtrue; qboolean sdlToggled = qfalse; SDL_Surface *s = SDL_GetVideoSurface( ); if( s ) { // Find out the current state fullscreen = !!( s->flags & SDL_FULLSCREEN ); if( r_fullscreen->integer && Cvar_VariableIntegerValue( "in_nograb" ) ) { ri.Printf( PRINT_ALL, "Fullscreen not allowed with in_nograb 1\n"); ri.Cvar_Set( "r_fullscreen", "0" ); r_fullscreen->modified = qfalse; } // Is the state we want different from the current state? needToToggle = !!r_fullscreen->integer != fullscreen; if( needToToggle ) sdlToggled = SDL_WM_ToggleFullScreen( s ); } if( needToToggle ) { // SDL_WM_ToggleFullScreen didn't work, so do it the slow way if( !sdlToggled ) Cbuf_AddText( "vid_restart" ); IN_Restart( ); } r_fullscreen->modified = qfalse; } }
int main(int argc, char** argv) { int width; int height; SDL_Surface* screen; SDL_Rect** modes; int videoFlags = SDL_OPENGL | SDL_FULLSCREEN; int done = 0; SDL_Event event; argc; argv; if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { panic("SDL Init"); } modes = SDL_ListModes(NULL, videoFlags); if(modes == NULL) { panic("No available video modes"); } width = 240; height = 320; if(modes != (SDL_Rect**) -1) { width = modes[0]->w; height = modes[0]->h; } // SDL_GL_LoadLibrary(NULL); screen = SDL_SetVideoMode(width, height, 16, videoFlags); if(screen == NULL) { panic("No GLES surface available"); } /*glDisable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); glClearColor(0.f, 0.f, 0.1f, 1.f); glVertexPointer(3, GL_BYTE, 0, vertices); glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);*/ glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glViewport(0, 0, width, height); //glMatrixMode(GL_PROJECTION); //glFrustumf(-1.f, 1.f, -1.f, 1.f, 3.f, 1000.f); //glMatrixMode(GL_MODELVIEW); while(!done) { if(SDL_PollEvent(&event)) { switch(event.type) { case SDL_KEYDOWN: case SDL_QUIT: done = 1; break; } } else { GLenum gl_error; renderFrame(); EGL_SwapBuffers(); /* Check for error conditions. */ gl_error = glGetError(); if(gl_error != GL_NO_ERROR ) { fprintf(stderr, "OpenGL error: %d\n", gl_error ); SDL_FreeSurface(screen); SDL_Quit(); exit( 1 ); } SDL_Delay(20); } } SDL_FreeSurface(screen); /* Shutdown all subsystems */ SDL_Quit(); return 0; }
void sludgeDisplay () { #if defined(HAVE_GLES2) #ifndef GL_DEPTH24_STENCIL8 #define GL_DEPTH24_STENCIL8 0x88F0 #endif // create an FBO static GLuint fbo = 0; static GLuint fbo_tex = 0; static GLuint fbo_rbo = 0; static float fbo_tex_w, fbo_tex_h; static GLuint fbo_shad, fbo_vert, fbo_frag; if(fbo==0) { // create FBO int width = 1; while (width<realWinWidth) width *= 2; int height = 1; while (height<realWinHeight) height *= 2; glGenFramebuffers(1, &fbo); glGenTextures(1, &fbo_tex); glGenRenderbuffers(1, &fbo_rbo); glBindTexture(GL_TEXTURE_2D, fbo_tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glBindTexture(GL_TEXTURE_2D, 0); glBindRenderbuffer(GL_RENDERBUFFER, fbo_rbo); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height); glBindRenderbuffer(GL_RENDERBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, fbo); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbo_tex, 0); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fbo_rbo); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, fbo_rbo); GLenum ret = glCheckFramebufferStatus(GL_FRAMEBUFFER); printf("Screen is %dx%d, FBO(%dx%d) Status = 0x%04X\n", realWinWidth, realWinHeight, width, height, ret); glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, fbo); fbo_tex_w = (float)realWinWidth / width; fbo_tex_h = (float)realWinHeight / height; // create shader for blitting the fbo... const char _blit_vsh[] = " \n\t" \ "attribute highp vec2 aPosition; \n\t" \ "attribute highp vec2 aTexCoord; \n\t" \ "varying mediump vec2 vTexCoord; \n\t" \ "void main(){ \n\t" \ "gl_Position = vec4(aPosition.x, aPosition.y, 0.0, 1.0);\n\t" \ "vTexCoord = aTexCoord; \n\t" \ "} \n\t"; const char _blit_fsh[] = " \n\t" \ "uniform sampler2D uTex; \n\t" \ "varying mediump vec2 vTexCoord; \n\t" \ "void main(){ \n\t" \ "gl_FragColor = texture2D(uTex, vTexCoord); \n\t" \ "} \n\t"; GLint success; fbo_frag = glCreateShader( GL_FRAGMENT_SHADER ); const char* src[1]; src[0] = _blit_fsh; glShaderSource( fbo_frag, 1, src, NULL ); glCompileShader( fbo_frag ); glGetShaderiv( fbo_frag, GL_COMPILE_STATUS, &success ); if (!success) { printf("Failed to produce default fragment shader.\n"); } fbo_vert = glCreateShader( GL_VERTEX_SHADER ); src[0] = _blit_vsh; glShaderSource( fbo_vert, 1, src, NULL ); glCompileShader( fbo_vert ); glGetShaderiv( fbo_vert, GL_COMPILE_STATUS, &success ); if( !success ) { printf( "Failed to produce default vertex shader.\n" ); } fbo_shad = glCreateProgram(); glBindAttribLocation( fbo_shad, 0, "aPosition" ); glBindAttribLocation( fbo_shad, 1, "aTexCoord" ); glAttachShader( fbo_shad, fbo_frag ); glAttachShader( fbo_shad, fbo_vert ); glLinkProgram( fbo_shad ); glGetProgramiv( fbo_shad, GL_LINK_STATUS, &success ); if( !success ) { printf( "Failed to link default program.\n" ); } glUniform1i( glGetUniformLocation( fbo_shad, "uTex" ), 0 ); } #endif glDepthMask (GL_TRUE); // glClearColor(0.5, 0.5, 1.0, 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen glDepthMask (GL_FALSE); drawBackDrop (); // Draw the room drawZBuffer(cameraX, cameraY, false); glEnable(GL_DEPTH_TEST); drawPeople (); // Then add any moving characters... glDisable(GL_DEPTH_TEST); viewSpeech (); // ...and anything being said drawStatusBar (); displayCursor (); if (brightnessLevel < 255) fixBrightness (); // This is for transitionLevel special effects glFlush(); #if !defined(HAVE_GLES2) SDL_GL_SwapBuffers(); #else if(fbo) { // blit the FBO now glBindFramebuffer(GL_FRAMEBUFFER, 0); GLuint old_prog; glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*)&old_prog); glUseProgram(fbo_shad); glViewport(0, 0, realWinWidth, realWinHeight); const float vert[] = { -1.0, -1.0, +0.0, +0.0, +1.0, -1.0, fbo_tex_w, +0.0, -1.0, +1.0, +0.0, fbo_tex_h, +1.0, +1.0, fbo_tex_w, fbo_tex_h }; glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, fbo_tex); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (float*)vert); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (float*)vert + 2); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glBindTexture(GL_TEXTURE_2D, 0); glUseProgram(old_prog); glViewport (viewportOffsetX, viewportOffsetY, viewportWidth, viewportHeight); } EGL_SwapBuffers(); if(fbo) { // Rebind FBO now glBindFramebuffer(GL_FRAMEBUFFER, fbo); } #endif }