OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Skybox.java
Go to the documentation of this file.
1 /* Copyright (c) 2014-2017, ARM Limited and Contributors
2  *
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge,
6  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  */
20 
21 package com.arm.malideveloper.openglessdk.skybox;
22 
23 import java.io.File;
24 import java.io.InputStream;
25 import java.io.RandomAccessFile;
26 
27 import android.os.Bundle;
28 import android.app.Activity;
29 import android.content.res.AssetManager;
30 import android.util.Log;
31 
32 public class Skybox extends Activity
33 {
34  /* [classMembers] */
35  private static String LOGTAG = "Skybox";
36  private static String assetDirectory = null;
37  protected TutorialView graphicsView;
38 
39  private static android.content.Context applicationContext = null;
40  /* [classMembers] */
41  @Override
42  protected void onCreate(Bundle savedInstanceState)
43  {
44  super.onCreate(savedInstanceState);
45  graphicsView = new TutorialView(getApplication());
46 
47  /* [onCreateNew] */
48  applicationContext = getApplicationContext();
49  assetDirectory = applicationContext.getFilesDir().getPath() + "/";
50 
51  extractAsset("font.raw");
52  extractAsset("font.png");
53  extractAsset("font.vert");
54  extractAsset("font.frag");
55  extractAsset("shader.vert");
56  extractAsset("shader.frag");
57  extractAsset("greenhouse_skybox-0.ppm");
58  extractAsset("greenhouse_skybox-1.ppm");
59  extractAsset("greenhouse_skybox-2.ppm");
60  extractAsset("greenhouse_skybox-3.ppm");
61  extractAsset("greenhouse_skybox-4.ppm");
62  extractAsset("greenhouse_skybox-5.ppm");
63 
64  /* [onCreateNew] */
65  setContentView(graphicsView);
66  }
67  @Override protected void onPause()
68  {
69  super.onPause();
70  graphicsView.onPause();
71  }
72  @Override protected void onResume()
73  {
74  super.onResume();
75  graphicsView.onResume();
76  }
77  @Override protected void onDestroy()
78  {
79  super.onDestroy();
80  }
81  /* [extractAssetBeginning] */
82  private void extractAsset(String assetName)
83  {
84  File fileTest = new File(assetDirectory + assetName);
85 
86  if(fileTest.exists())
87  {
88  Log.d(LOGTAG,assetName + " already exists. No extraction needed.\n");
89  }
90  else
91  {
92  Log.d(LOGTAG, assetName + " doesn't exist. Extraction needed. \n");
93  /* [extractAssetBeginning] */
94  /* [tryCatch extractAsset] */
95  try
96  {
97  RandomAccessFile out = new RandomAccessFile(assetDirectory + assetName,"rw");
98  AssetManager am = applicationContext.getResources().getAssets();
99  /* [tryCatch extractAsset] */
100  /* [readWriteFile] */
101  InputStream inputStream = am.open(assetName);
102  byte buffer[] = new byte[1024];
103  int count = inputStream.read(buffer, 0, 1024);
104 
105  while (count > 0)
106  {
107  out.write(buffer, 0, count);
108  count = inputStream.read(buffer, 0, 1024);
109  }
110  out.close();
111  inputStream.close();
112  }
113  catch(Exception e)
114  {
115  Log.e(LOGTAG, "Failure in extractAssets(): " + e.toString() + " " + assetDirectory+assetName);
116  }
117  if(fileTest.exists())
118  {
119  Log.d(LOGTAG,"File extracted successfully");
120  /* [readWriteFile] */
121  }
122  }
123  }
124 }
static android.content.Context applicationContext
Definition: Skybox.java:39
GLenum GLenum GLsizei count
Definition: gl2ext.h:133
GLenum GLuint buffer
Definition: gl2ext.h:628
void onCreate(Bundle savedInstanceState)
Definition: Skybox.java:42