~diegosarmentero/nuxplayground/nux-view-html-typos

« back to all changes in this revision

Viewing changes to src/nux-gfx-copy-back-buffer/nux-gfx-copy-back-buffer.cpp

  • Committer: Jay Taoko
  • Date: 2012-07-12 18:34:56 UTC
  • mfrom: (20.1.1 nuxp.timer-api)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: jay.taoko@canonical.com-20120712183456-ednq5vf65rixzlsx
* Added demo programs
* Added markdown script and syntax highlighting script
* Cleanup and fixes
* Added documentation folder

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "NuxCore/NuxCore.h"
 
2
#include "NuxGraphics/BitmapFormats.h"
 
3
#include "NuxGraphics/GraphicsDisplay.h"
 
4
#include "NuxGraphics/GLWindowManager.h"
 
5
#include "NuxGraphics/GraphicsEngine.h"
 
6
#include "NuxCore/FilePath.h"
 
7
 
 
8
#if defined(NUX_OS_WINDOWS)
 
9
  #define PKGDATADIR "../../data/"
 
10
#endif
 
11
 
 
12
void TextureCopyBlurTest()
 
13
{
 
14
  nux::GraphicsDisplay* graphics_display = gGLWindowManager.CreateGLWindow("Window", 600, 300, nux::WINDOWSTYLE_NORMAL, 0, false);
 
15
  nux::GraphicsEngine* graphics_engine = graphics_display->GetGraphicsEngine();
 
16
 
 
17
  graphics_display->ShowWindow();
 
18
 
 
19
  nux::ObjectPtr<nux::IOpenGLFrameBufferObject> fbo;
 
20
  nux::ObjectPtr<nux::IOpenGLBaseTexture> texture_rt;
 
21
  nux::ObjectPtr<nux::IOpenGLBaseTexture> depth_rt;
 
22
 
 
23
  fbo         = graphics_display->GetGpuDevice ()->CreateFrameBufferObject ();
 
24
  texture_rt  = graphics_display->GetGpuDevice ()->CreateSystemCapableDeviceTexture (graphics_display->GetWindowWidth(), graphics_display->GetWindowHeight(), 1, nux::BITFMT_R8G8B8A8);
 
25
  depth_rt    = graphics_display->GetGpuDevice ()->CreateSystemCapableDeviceTexture (graphics_display->GetWindowWidth(), graphics_display->GetWindowHeight(), 1, nux::BITFMT_D24S8);
 
26
 
 
27
 
 
28
  int w, h;
 
29
  graphics_engine->GetWindowSize(w, h);
 
30
  graphics_engine->SetViewport(0, 0, w, h);
 
31
  graphics_engine->SetOrthographicProjectionMatrix(w, h);
 
32
 
 
33
  nux::Event event;
 
34
  memset(&event, 0, sizeof(nux::Event));
 
35
 
 
36
  char fps [25];
 
37
  int frame_counter = 0;
 
38
  int frame_periode = 0;
 
39
  float frame_rate = 0;
 
40
  float periode_time = 0;
 
41
  bool first_time = true;
 
42
  do
 
43
  {
 
44
    CHECKGL( glClearColor(0, 0, 0, 1) );
 
45
    CHECKGL( glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT) );
 
46
 
 
47
    graphics_display->GetSystemEvent(&event);
 
48
    if(first_time || (event.type == nux::NUX_SIZE_CONFIGURATION))
 
49
    {
 
50
      first_time = false;
 
51
      graphics_engine->DisableAllTextureMode(0);
 
52
      graphics_engine->DisableAllTextureMode(1);
 
53
      graphics_engine->DisableAllTextureMode(2);
 
54
      graphics_engine->DisableAllTextureMode(3);
 
55
      //graphics_engine->SetEnvModeSelectTexture(GL_TEXTURE0);
 
56
      graphics_engine->GetWindowSize(w, h);
 
57
      graphics_engine->SetViewport(0, 0, w, h);
 
58
      graphics_engine->SetScissor(0, 0, w, h);
 
59
      graphics_engine->SetOrthographicProjectionMatrix(w, h);
 
60
 
 
61
      fbo         = graphics_display->GetGpuDevice ()->CreateFrameBufferObject ();
 
62
      texture_rt  = graphics_display->GetGpuDevice ()->CreateSystemCapableDeviceTexture (graphics_display->GetWindowWidth(), graphics_display->GetWindowHeight(), 1, nux::BITFMT_R8G8B8A8);
 
63
      depth_rt    = graphics_display->GetGpuDevice ()->CreateSystemCapableDeviceTexture (graphics_display->GetWindowWidth(), graphics_display->GetWindowHeight(), 1, nux::BITFMT_D24S8);
 
64
      fbo->FormatFrameBufferObject (graphics_display->GetWindowWidth(), graphics_display->GetWindowHeight(), nux::BITFMT_R8G8B8A8);
 
65
    }
 
66
 
 
67
    fbo->SetRenderTarget (0, texture_rt->GetSurfaceLevel (0));
 
68
    fbo->SetDepthSurface (depth_rt->GetSurfaceLevel (0));
 
69
    fbo->Activate();
 
70
 
 
71
 
 
72
    //     graphics_engine->GetWindowSize(w, h);
 
73
    //     graphics_engine->SetViewport(0, 0, w, h);
 
74
    //     graphics_engine->SetOrthographicProjectionMatrix(w, h);
 
75
 
 
76
    for (int i = 0; i < 1; i++)
 
77
    {
 
78
      nux::Rect geo (nux::RandomUInt(graphics_display->GetWindowWidth()),
 
79
        nux::RandomUInt(graphics_display->GetWindowHeight()),
 
80
        nux::RandomUInt(200),
 
81
        nux::RandomUInt(200));
 
82
 
 
83
      graphics_engine->QRP_Color(geo.x, geo.y, geo.width, geo.height, nux::color::RandomColor());
 
84
    }
 
85
 
 
86
    nux::TexCoordXForm texxform;
 
87
    // Make a copy of the render target
 
88
    nux::ObjectPtr <nux::IOpenGLBaseTexture> tex_copy = graphics_engine->CreateTextureFromBackBuffer (0, 0, graphics_display->GetWindowWidth (), graphics_display->GetWindowHeight ());
 
89
 
 
90
    // Restore the back buffer
 
91
    graphics_display->GetGpuDevice ()->DeactivateFrameBuffer ();
 
92
 
 
93
    // Make a blurred version of the back buffer
 
94
    nux::ObjectPtr <nux::IOpenGLBaseTexture> tex_blur = graphics_engine->QRP_GLSL_GetBlurTexture (
 
95
      0, 0, texture_rt->GetWidth (), texture_rt->GetHeight (),
 
96
      texture_rt, texxform, nux::color::White);
 
97
 
 
98
    // Render the blurred texture
 
99
    graphics_engine->QRP_1Tex(0, 0, tex_blur->GetWidth(), tex_blur->GetHeight(), tex_blur, texxform, nux::color::White);
 
100
 
 
101
    sprintf(fps, "FPS: %3.2f", frame_rate);
 
102
    nux::PageBBox page;
 
103
    page.xmin = 0;
 
104
    page.xmax = 100;
 
105
    page.ymin = 0;
 
106
    page.ymax = 20;
 
107
    page.x_margin = 0;
 
108
    page.y_margin = 0;
 
109
    graphics_engine->RenderColorTextLineStatic(graphics_engine->GetBoldFont (), page, fps, nux::color::White, false, nux::eAlignTextLeft);    
 
110
 
 
111
    graphics_display->SwapBuffer();
 
112
 
 
113
    float frame_time = graphics_display->GetFrameTime();
 
114
    graphics_display->ResetFrameTime();
 
115
    periode_time += frame_time;
 
116
 
 
117
    frame_counter++;
 
118
    frame_periode++;
 
119
 
 
120
    if (frame_periode >= 100)
 
121
    {
 
122
      frame_rate = frame_periode * 1000.0f / periode_time;
 
123
      periode_time = 0.0f;
 
124
      frame_periode = 0;
 
125
    }
 
126
 
 
127
  } while((event.type != nux::NUX_TERMINATE_APP) && (event.GetVirtualKeyState(NUX_VK_ESCAPE) == 0));
 
128
 
 
129
  fbo.Release ();
 
130
  texture_rt.Release ();
 
131
  depth_rt.Release ();
 
132
 
 
133
  delete graphics_display;
 
134
}
 
135
 
 
136
 
 
137
int main(int argc, char **argv)
 
138
{
 
139
  nux::NuxCoreInitialize(0);
 
140
  nux::NuxGraphicsInitialize();
 
141
 
 
142
  TextureCopyBlurTest ();
 
143
  return 0;
 
144
}
 
 
b'\\ No newline at end of file'