O'Reilly logo

OpenGL ES 2 for Android by Kevin Brothaler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required