OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This is a simple example that draws a quad with a 2D | 5 // This is a simple example that draws a quad with a 2D |
6 // texture image. The purpose of this example is to demonstrate | 6 // texture image. The purpose of this example is to demonstrate |
7 // the basics of 2D texturing | 7 // the basics of 2D texturing |
8 | 8 |
9 #include "gpu/demos/app_framework/application.h" | 9 #include "gpu/demos/app_framework/application.h" |
10 #include "third_party/gles2_book/Chapter_9/Simple_Texture2D/Simple_Texture2D.h" | 10 #include "third_party/gles2_book/Chapter_9/Simple_Texture2D/Simple_Texture2D.h" |
11 | 11 |
12 namespace gpu_demos { | 12 namespace gpu_demos { |
13 class SimpleTexture2D : public Application { | 13 class SimpleTexture2D : public Application { |
14 public: | 14 public: |
15 SimpleTexture2D(); | 15 SimpleTexture2D(); |
16 ~SimpleTexture2D(); | 16 ~SimpleTexture2D(); |
17 | 17 |
18 bool Init(); | 18 bool Init(); |
19 | 19 |
20 protected: | 20 protected: |
21 virtual void Draw(float); | 21 virtual void Draw(float elapsed_sec); |
22 | 22 |
23 private: | 23 private: |
24 ESContext context_; | 24 ESContext context_; |
25 STUserData user_data_; | 25 STUserData user_data_; |
26 | 26 |
27 DISALLOW_COPY_AND_ASSIGN(SimpleTexture2D); | 27 DISALLOW_COPY_AND_ASSIGN(SimpleTexture2D); |
28 }; | 28 }; |
29 | 29 |
30 SimpleTexture2D::SimpleTexture2D() { | 30 SimpleTexture2D::SimpleTexture2D() { |
31 esInitContext(&context_); | 31 esInitContext(&context_); |
32 | 32 |
33 memset(&user_data_, 0, sizeof(STUserData)); | 33 memset(&user_data_, 0, sizeof(STUserData)); |
34 context_.userData = &user_data_; | 34 context_.userData = &user_data_; |
35 } | 35 } |
36 | 36 |
37 SimpleTexture2D::~SimpleTexture2D() { | 37 SimpleTexture2D::~SimpleTexture2D() { |
38 stShutDown(&context_); | 38 stShutDown(&context_); |
39 } | 39 } |
40 | 40 |
41 bool SimpleTexture2D::Init() { | 41 bool SimpleTexture2D::Init() { |
42 if (!Application::InitRenderContext()) return false; | 42 if (!Application::InitRenderContext()) return false; |
43 | 43 |
44 context_.width = width(); | 44 context_.width = width(); |
45 context_.height = height(); | 45 context_.height = height(); |
46 if (!stInit(&context_)) return false; | 46 if (!stInit(&context_)) return false; |
47 | 47 |
48 return true; | 48 return true; |
49 } | 49 } |
50 | 50 |
51 void SimpleTexture2D::Draw(float) { | 51 void SimpleTexture2D::Draw(float /*elapsed_sec*/) { |
52 stDraw(&context_); | 52 stDraw(&context_); |
53 } | 53 } |
54 } // namespace gpu_demos | 54 } // namespace gpu_demos |
55 | 55 |
56 int main(int argc, char *argv[]) { | 56 int main(int argc, char *argv[]) { |
57 gpu_demos::SimpleTexture2D app; | 57 gpu_demos::SimpleTexture2D app; |
58 if (!app.Init()) { | 58 if (!app.Init()) { |
59 printf("Could not init.\n"); | 59 printf("Could not init.\n"); |
60 return EXIT_FAILURE; | 60 return EXIT_FAILURE; |
61 } | 61 } |
62 | 62 |
63 app.MainLoop(); | 63 app.MainLoop(); |
64 return EXIT_SUCCESS; | 64 return EXIT_SUCCESS; |
65 } | 65 } |
OLD | NEW |