Loading Shaders
Now that we’ve written the code for our shaders, the next step is to load them into memory. To do that, we’ll first need to write a method to read in the code from our resources folder.
Loading Text from a Resource
Create a new Java source package in your project, com.airhockey.android.util, and in that package, create a new class called TextResourceReader. Add the following code inside the class:
AirHockey1/src/com/airhockey/android/util/TextResourceReader.java | |
| public static String readTextFileFromResource(Context context, |
| int resourceId) { |
| StringBuilder body = new StringBuilder(); |
| |
| try { |
| InputStream inputStream = |
| context.getResources().openRawResource(resourceId); |
| InputStreamReader inputStreamReader ... |
Get OpenGL ES 2 for Android now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.