Skip to content

Commit

Permalink
Added Lesson 7 - vertex buffer objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
learnopengles committed Mar 6, 2012
1 parent d7984b1 commit 65077f2
Show file tree
Hide file tree
Showing 20 changed files with 2,200 additions and 5 deletions.
3 changes: 2 additions & 1 deletion android/AndroidOpenGLESLessons/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
10 changes: 10 additions & 0 deletions android/AndroidOpenGLESLessons/AUTHORS-LIBGDX.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This is the official list of the AUTHORS of libgdx
# for copyright purposes.
# This file is distinct from the CONTRIBUTORS files.
# See the latter for an explanation.

# Names should be added to this file as
# Name or Organization <email address>
# The email address is not required for organizations.
Mario Zechner <badlogicgames@gmail.com>
Nathan Sweet <nathan.sweet@gmail.com>
5 changes: 4 additions & 1 deletion android/AndroidOpenGLESLessons/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.learnopengles.android"
android:versionCode="7" android:versionName="1.0.5">
android:versionCode="8" android:versionName="1.0.6">
<uses-sdk
android:minSdkVersion="8" />
<!-- We require OpenGL ES 2.0 -->
Expand Down Expand Up @@ -41,5 +41,8 @@
<activity
android:label="@string/lesson_six"
android:name=".lesson6.LessonSixActivity"/>
<activity
android:label="@string/lesson_seven"
android:name=".lesson7.LessonSevenActivity"/>
</application>
</manifest>
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions android/AndroidOpenGLESLessons/lint.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
</lint>
8 changes: 6 additions & 2 deletions android/AndroidOpenGLESLessons/proguard.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@
native <methods>;
}

-keepclasseswithmembernames class * {
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembernames class * {
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}

-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions android/AndroidOpenGLESLessons/res/layout/lesson_seven.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.learnopengles.android.lesson7.LessonSevenGLSurfaceView
android:id="@+id/gl_surface_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:orientation="horizontal">
<Button
android:id="@+id/button_decrease_num_cubes"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="@string/lesson_seven_decrease_cube_count" />
<Button
android:id="@+id/button_increase_num_cubes"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="@string/lesson_seven_increase_cube_count" />
<Button
android:id="@+id/button_switch_VBOs"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="@string/lesson_seven_using_VBOs" />
<Button
android:id="@+id/button_switch_stride"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="@string/lesson_seven_using_stride" />
</LinearLayout>

</FrameLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
precision mediump float; // Set the default precision to medium. We don't need as high of a
// precision in the fragment shader.
uniform vec3 u_LightPos; // The position of the light in eye space.
uniform sampler2D u_Texture; // The input texture.

varying vec3 v_Position; // Interpolated position for this fragment.
varying vec3 v_Normal; // Interpolated normal for this fragment.
varying vec2 v_TexCoordinate; // Interpolated texture coordinate per fragment.

// The entry point for our fragment shader.
void main()
{
// Will be used for attenuation.
float distance = length(u_LightPos - v_Position);

// Get a lighting direction vector from the light to the vertex.
vec3 lightVector = normalize(u_LightPos - v_Position);

// Calculate the dot product of the light vector and vertex normal. If the normal and light vector are
// pointing in the same direction then it will get max illumination.
float diffuse = max(dot(v_Normal, lightVector), 0.0);

// Add attenuation.
diffuse = diffuse * (1.0 / distance);

// Add ambient lighting
diffuse = diffuse + 0.2;

// Multiply the color by the diffuse illumination level and texture value to get final output color.
gl_FragColor = (diffuse * texture2D(u_Texture, v_TexCoordinate));
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
uniform mat4 u_MVPMatrix; // A constant representing the combined model/view/projection matrix.
uniform mat4 u_MVMatrix; // A constant representing the combined model/view matrix.

attribute vec4 a_Position; // Per-vertex position information we will pass in.
attribute vec3 a_Normal; // Per-vertex normal information we will pass in.
attribute vec2 a_TexCoordinate; // Per-vertex texture coordinate information we will pass in.

varying vec3 v_Position; // This will be passed into the fragment shader.
varying vec3 v_Normal; // This will be passed into the fragment shader.
varying vec2 v_TexCoordinate; // This will be passed into the fragment shader.

// The entry point for our vertex shader.
void main()
{
// Transform the vertex into eye space.
v_Position = vec3(u_MVMatrix * a_Position);

// Pass through the texture coordinate.
v_TexCoordinate = a_TexCoordinate;

// Transform the normal's orientation into eye space.
v_Normal = vec3(u_MVMatrix * vec4(a_Normal, 0.0));

// gl_Position is a special variable used to store the final position.
// Multiply the vertex by the matrix to get the final point in normalized screen coordinates.
gl_Position = u_MVPMatrix * a_Position;
}
10 changes: 9 additions & 1 deletion android/AndroidOpenGLESLessons/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@
<item>GL_NEAREST</item>
<item>GL_LINEAR</item>
</string-array>
</resources>
<string name="lesson_seven">Lesson Seven: An Intro to VBOs</string>
<string name="lesson_seven_subtitle">This lesson looks at vertex buffer objects (VBOs).</string>
<string name="lesson_seven_increase_cube_count">Increase cube count</string>
<string name="lesson_seven_decrease_cube_count">Decrease cube count</string>
<string name="lesson_seven_using_VBOs">Using VBOs</string>
<string name="lesson_seven_not_using_VBOs">Not using VBOs</string>
<string name="lesson_seven_using_stride">Using stride</string>
<string name="lesson_seven_not_using_stride">Not using stride</string>
</resources>
Loading

0 comments on commit 65077f2

Please sign in to comment.