nux-1.16.0
|
00001 /* 00002 * Copyright 2010 Inalogic Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU General Public License version 3, as published 00006 * by the Free Software Foundation. 00007 * 00008 * This program is distributed in the hope that it will be useful, but 00009 * WITHOUT ANY WARRANTY; without even the implied warranties of 00010 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00011 * PURPOSE. See the GNU General Public License for more details. 00012 * 00013 * You should have received a copy of the GNU General Public License 00014 * version 3 along with this program. If not, see 00015 * <http://www.gnu.org/licenses/> 00016 * 00017 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00018 * 00019 */ 00020 00021 00022 #include "NuxCore/NuxCore.h" 00023 #include "NuxImage/BitmapFormats.h" 00024 #include "NuxGraphics/GraphicsDisplay.h" 00025 #include "NuxGraphics/GLWindowManager.h" 00026 #include "NuxGraphics/GraphicsEngine.h" 00027 00028 /* 00029 * Tests: 00030 * - frame buffer object 00031 * - Set a texture in the fbo 00032 * - Set fbo as a render target 00033 * - Render Quad to fbo 00034 * - Use fbo texture to draw a full screen quad on the default render target 00035 */ 00036 00037 void RenderToFrameBufferObject () 00038 { 00039 nux::GraphicsDisplay* graphics_display = gGLWindowManager.CreateGLWindow("Window", 570, 270, nux::WINDOWSTYLE_NORMAL, 0, false); 00040 nux::GraphicsEngine* graphics_engine = graphics_display->GetGraphicsEngine(); 00041 00042 graphics_display->ShowWindow(); 00043 00044 nux::ObjectPtr<nux::IOpenGLFrameBufferObject> fbo; 00045 nux::ObjectPtr<nux::IOpenGLBaseTexture> texture_rt; 00046 nux::ObjectPtr<nux::IOpenGLBaseTexture> depth_rt; 00047 00048 fbo = graphics_display->GetGpuDevice ()->CreateFrameBufferObject (); 00049 texture_rt = graphics_display->GetGpuDevice ()->CreateSystemCapableDeviceTexture (graphics_display->GetWindowWidth(), graphics_display->GetWindowHeight(), 1, nux::BITFMT_R8G8B8A8); 00050 depth_rt = graphics_display->GetGpuDevice ()->CreateSystemCapableDeviceTexture (graphics_display->GetWindowWidth(), graphics_display->GetWindowHeight(), 1, nux::BITFMT_D24S8); 00051 00052 00053 int w, h; 00054 graphics_engine->GetWindowSize(w, h); 00055 graphics_engine->SetViewport(0, 0, w, h); 00056 graphics_engine->SetContext(0, 0, w, h); 00057 graphics_engine->Push2DWindow(w, h); 00058 00059 nux::IEvent event; 00060 memset(&event, 0, sizeof(nux::IEvent)); 00061 00062 do 00063 { 00064 CHECKGL( glClearColor(0, 0, 0, 1) ); 00065 CHECKGL( glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT) ); 00066 00067 graphics_display->GetSystemEvent(&event); 00068 if(event.e_event == nux::NUX_SIZE_CONFIGURATION) 00069 { 00070 graphics_engine->DisableAllTextureMode(0); 00071 graphics_engine->DisableAllTextureMode(1); 00072 graphics_engine->DisableAllTextureMode(2); 00073 graphics_engine->DisableAllTextureMode(3); 00074 graphics_engine->GetWindowSize(w, h); 00075 graphics_engine->SetViewport(0, 0, w, h); 00076 graphics_engine->SetScissor(0, 0, w, h); 00077 graphics_engine->SetContext(0, 0, w, h); 00078 graphics_engine->Push2DWindow(w, h); 00079 00080 fbo = graphics_display->GetGpuDevice ()->CreateFrameBufferObject (); 00081 texture_rt = graphics_display->GetGpuDevice ()->CreateSystemCapableDeviceTexture (graphics_display->GetWindowWidth(), graphics_display->GetWindowHeight(), 1, nux::BITFMT_R8G8B8A8); 00082 depth_rt = graphics_display->GetGpuDevice ()->CreateSystemCapableDeviceTexture (graphics_display->GetWindowWidth(), graphics_display->GetWindowHeight(), 1, nux::BITFMT_D24S8); 00083 } 00084 00085 fbo->FormatFrameBufferObject (graphics_display->GetWindowWidth(), graphics_display->GetWindowHeight(), nux::BITFMT_R8G8B8A8); 00086 fbo->SetRenderTarget (0, texture_rt->GetSurfaceLevel (0)); 00087 fbo->SetDepthSurface (depth_rt->GetSurfaceLevel (0)); 00088 fbo->Activate(); 00089 00090 graphics_engine->GetWindowSize(w, h); 00091 graphics_engine->SetViewport(0, 0, w, h); 00092 graphics_engine->SetContext(0, 0, w, h); 00093 graphics_engine->Push2DWindow(w, h); 00094 00095 nux::Rect geo (nux::RandomUInt(graphics_display->GetWindowWidth()), 00096 nux::RandomUInt(graphics_display->GetWindowHeight()), 00097 nux::RandomUInt(200), 00098 nux::RandomUInt(200)); 00099 00100 graphics_engine->QRP_Color(geo.x, geo.y, geo.width, geo.height, nux::color::RandomColor()); 00101 00102 graphics_display->GetGpuDevice ()->DeactivateFrameBuffer (); 00103 00104 nux::TexCoordXForm texxform; 00105 graphics_engine->QRP_1Tex(0, 0, graphics_display->GetWindowWidth(), graphics_display->GetWindowHeight(), texture_rt, texxform, nux::color::White); 00106 00107 graphics_display->SwapBuffer(); 00108 } while(event.e_event != nux::NUX_TERMINATE_APP); 00109 00110 fbo.Release (); 00111 texture_rt.Release (); 00112 depth_rt.Release (); 00113 00114 delete graphics_display; 00115 } 00116 00117 int main(int argc, char **argv) 00118 { 00119 nux::NuxCoreInitialize(0); 00120 nux::NuxGraphicsInitialize(); 00121 00122 RenderToFrameBufferObject (); 00123 00124 return 0; 00125 } 00126