3D Views: Source Code

Page 5

RawResourceHeader

This Java code is modified from Learn OpenGL ES code posted on GitHub. The WebGL tutorials can be found at http://www.learnopengles.com.

Introduction Java Code Summary

Introduction

The RawResourceHeader class reads text from raw resources. The text, for this example, includes vertex and fragment shaders.

Java Code

package com.seventhundersoftware.cubeview.common;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import android.content.Context;

public class RawResourceReader
{

/***
Read in a resource integer ID.
Return a string.
@param context: Context
@param resourceId: integer
@returns: String
**/
public static String readTextFileFromRawResource(final Context context,
	final int resourceId)
{
final InputStream inputStream = context.getResources().openRawResource(
		resourceId);
final InputStreamReader inputStreamReader = new InputStreamReader(
		inputStream);
final BufferedReader bufferedReader = new BufferedReader(
		inputStreamReader);

String nextLine;
final StringBuilder body = new StringBuilder();

try
{
while ((nextLine = bufferedReader.readLine()) != null)
{
body.append(nextLine);
body.append('\n');
}
}
catch (IOException e)
{
return null;
}

return body.toString();
}
}

Summary

The RawResourceHeader class reads text from raw resources. The text, for this example, includes vertex and fragment shaders.

Java & OpenGL ES

This set of pages include Android Java, combined with OpenGL ES, to display a set of simple three dimensional views. The views apply a unique, simple concept to render 3D backgrounds, without Skyboxes or time consuming shader switching. Each view's contained in one graphic, with room for other sprites and meshes.

Java and OpenGL ES source code was ported from WebGL with only minor changes. The book, 3D Scenes: Learn WebGL Book 3, explains implementation and graphics preparation for the WebGL app, in detail.

Tags

Free source code, free Java, free OpenGL ES, 3D programming, learn to code,

Ads >
Create 3D Games: Learn WebGL Book 2 Simple Shaders: Learn WebGL Book 4
3D Programming for Beginners: Learn WebGL Book 1
Web Graphics & Illustration Architectural Rendering 3D Architectural Web Animation
Web Development Python & MySQL Send Email Complete Sitemap About Search 3D