Android Open Source - Freebloks-Android Background Renderer From Project Back to project page Freebloks-Android .
License The source code is released under:
GNU General Public License
If you think the Android project Freebloks-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code package de.saschahlusiak.freebloks.view;
/ / f r o m w w w . j a v a 2 s . c o m
import javax.microedition.khronos.opengles.GL10;
import javax.microedition.khronos.opengles.GL11;
import de.saschahlusiak.freebloks.view.model.Theme;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.opengl.GLUtils;
public class BackgroundRenderer extends SimpleModel {
float rgba[] = { 0, 0, 0, 1 };
int texture[];
boolean hasTexture;
final static int num_vertices = 4;
final static int num_triangles = 2;
final static float size = 80.0f;
final static float textures = 15.0f;
Theme theme;
Resources resources;
public BackgroundRenderer(Resources resources) {
super (num_vertices, num_triangles);
this.resources = resources;
hasTexture = false;
addVertex(-size, 0, -size, 0, 1, 0, 0, 0);
addVertex( size, 0, -size, 0, 1, 0, textures, 0);
addVertex( size, 0, size, 0, 1, 0, textures, textures);
addVertex(-size, 0, size, 0, 1, 0, 0, textures);
addIndex(0, 2, 1);
addIndex(0, 3, 2);
commit();
}
boolean valid = false;
public void setTheme(Theme theme) {
this.theme = theme;
valid = false;
}
public void updateTexture(GL10 gl) {
valid = true;
if (theme == null) {
rgba[0] = 0.0f; // transparent
rgba[1] = 0.0f;
rgba[2] = 0.0f;
rgba[3] = 0.0f;
hasTexture = false;
} else if (theme.isDrawable()) {
hasTexture = true;
texture = new int [1];
gl.glGenTextures(1, texture, 0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]);
if (gl instanceof GL11) {
gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR_MIPMAP_LINEAR);
gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
} else {
gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_GENERATE_MIPMAP, GL11.GL_FALSE);
}
gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
FreebloksRenderer.loadKTXTexture(gl, resources, theme.getTexture());
rgba = theme.getRGBA();
} else {
hasTexture = false;
rgba = theme.getRGBA();
}
}
final float specular[] = {0, 0, 0, 1};
public void render(GL10 gl) {
if (!valid)
updateTexture(gl);
if (hasTexture)
gl.glClearColor(0.05f, 0.10f, 0.25f, 1.0f); /* the default background when textured */
else
gl.glClearColor(rgba[0], rgba[1], rgba[2], rgba[3]);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
if (hasTexture) {
// float shininess[]={3.0f};
gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT_AND_DIFFUSE, rgba, 0);
gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_SPECULAR, specular, 0);
// gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_SHININESS, shininess, 0);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, getVertexBuffer());
gl.glNormalPointer(GL10.GL_FLOAT, 0, getNormalBuffer());
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, getTextureBuffer());
drawElements(gl);
gl.glDisable(GL10.GL_TEXTURE_2D);
}
}
}
Java Source Code List com.google.example.games.basegameutils.BaseGameActivity.java com.google.example.games.basegameutils.GameHelperUtils.java com.google.example.games.basegameutils.GameHelper.java de.saschahlusiak.freebloks.AboutActivity.java de.saschahlusiak.freebloks.Global.java de.saschahlusiak.freebloks.backup.FreebloksBackupAgent.java de.saschahlusiak.freebloks.controller.GameMode.java de.saschahlusiak.freebloks.controller.JNIServer.java de.saschahlusiak.freebloks.controller.PlayerData.java de.saschahlusiak.freebloks.controller.SpielClientInterface.java de.saschahlusiak.freebloks.controller.SpielClient.java de.saschahlusiak.freebloks.controller.Spielleiter.java de.saschahlusiak.freebloks.database.FreebloksDBOpenHandler.java de.saschahlusiak.freebloks.database.FreebloksDB.java de.saschahlusiak.freebloks.database.HighscoreDB.java de.saschahlusiak.freebloks.donate.DonateActivity.java de.saschahlusiak.freebloks.game.ActivityInterface.java de.saschahlusiak.freebloks.game.AddScoreTask.java de.saschahlusiak.freebloks.game.CustomGameDialog.java de.saschahlusiak.freebloks.game.FreebloksActivity.java de.saschahlusiak.freebloks.game.GameFinishActivity.java de.saschahlusiak.freebloks.game.GameMenu.java de.saschahlusiak.freebloks.game.RateAppDialog.java de.saschahlusiak.freebloks.game.RetainedConfig.java de.saschahlusiak.freebloks.game.SpielClientThread.java de.saschahlusiak.freebloks.lobby.ChatEntry.java de.saschahlusiak.freebloks.lobby.ChatListAdapter.java de.saschahlusiak.freebloks.lobby.ColorAdapter.java de.saschahlusiak.freebloks.lobby.LobbyDialog.java de.saschahlusiak.freebloks.model.Player.java de.saschahlusiak.freebloks.model.Spiel.java de.saschahlusiak.freebloks.model.Stone.java de.saschahlusiak.freebloks.model.Turn.java de.saschahlusiak.freebloks.model.Turnpool.java de.saschahlusiak.freebloks.network.NET_CHAT.java de.saschahlusiak.freebloks.network.NET_CURRENT_PLAYER.java de.saschahlusiak.freebloks.network.NET_GAME_FINISH.java de.saschahlusiak.freebloks.network.NET_GRANT_PLAYER.java de.saschahlusiak.freebloks.network.NET_HEADER.java de.saschahlusiak.freebloks.network.NET_REQUEST_GAME_MODE.java de.saschahlusiak.freebloks.network.NET_REQUEST_HINT.java de.saschahlusiak.freebloks.network.NET_REQUEST_PLAYER.java de.saschahlusiak.freebloks.network.NET_REQUEST_UNDO.java de.saschahlusiak.freebloks.network.NET_REVOKE_PLAYER.java de.saschahlusiak.freebloks.network.NET_SERVER_STATUS.java de.saschahlusiak.freebloks.network.NET_SET_STONE.java de.saschahlusiak.freebloks.network.NET_START_GAME.java de.saschahlusiak.freebloks.network.NET_UNDO_STONE.java de.saschahlusiak.freebloks.network.Network.java de.saschahlusiak.freebloks.preferences.AboutFragment.java de.saschahlusiak.freebloks.preferences.DisplayFragment.java de.saschahlusiak.freebloks.preferences.FreebloksPreferences.java de.saschahlusiak.freebloks.preferences.InterfaceFragment.java de.saschahlusiak.freebloks.preferences.MiscFragment.java de.saschahlusiak.freebloks.preferences.StatisticsFragment.java de.saschahlusiak.freebloks.preferences.ThemePreference.java de.saschahlusiak.freebloks.stats.StatisticsActivity.java de.saschahlusiak.freebloks.stats.StatisticsAdapter.java de.saschahlusiak.freebloks.view.BackgroundRenderer.java de.saschahlusiak.freebloks.view.BoardRenderer.java de.saschahlusiak.freebloks.view.Freebloks3DView.java de.saschahlusiak.freebloks.view.FreebloksRenderer.java de.saschahlusiak.freebloks.view.SimpleModel.java de.saschahlusiak.freebloks.view.effects.AbsEffect.java de.saschahlusiak.freebloks.view.effects.AbsStoneEffect.java de.saschahlusiak.freebloks.view.effects.BoardStoneGlowEffect.java de.saschahlusiak.freebloks.view.effects.EffectSet.java de.saschahlusiak.freebloks.view.effects.Effect.java de.saschahlusiak.freebloks.view.effects.PhysicalStoneEffect.java de.saschahlusiak.freebloks.view.effects.StoneFadeEffect.java de.saschahlusiak.freebloks.view.effects.StoneRollEffect.java de.saschahlusiak.freebloks.view.effects.StoneUndoEffect.java de.saschahlusiak.freebloks.view.model.Board.java de.saschahlusiak.freebloks.view.model.CurrentStone.java de.saschahlusiak.freebloks.view.model.Intro.java de.saschahlusiak.freebloks.view.model.Sounds.java de.saschahlusiak.freebloks.view.model.Theme.java de.saschahlusiak.freebloks.view.model.ViewElement.java de.saschahlusiak.freebloks.view.model.ViewModel.java de.saschahlusiak.freebloks.view.model.Wheel.java