-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Lesson 7 - vertex buffer objects.
- Loading branch information
1 parent
d7984b1
commit 65077f2
Showing
20 changed files
with
2,200 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<lint> | ||
</lint> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
41
android/AndroidOpenGLESLessons/res/layout/lesson_seven.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
32 changes: 32 additions & 0 deletions
32
android/AndroidOpenGLESLessons/res/raw/lesson_seven_fragment_shader.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
27 changes: 27 additions & 0 deletions
27
android/AndroidOpenGLESLessons/res/raw/lesson_seven_vertex_shader.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.