atlas book skeleton by Unknown

atlas book skeleton by Unknown

Author:Unknown
Language: eng
Format: mobi, epub


Helper utilities and other features

A utility class is one that contains miscellaneous helper methods that do not concretely fit into any other class. In essence, it is a random collection of useful things. Glitcher VR has one such class, aptly named Glitcher_Utils, that contains methods to compile shader programs, and save and load preferences between application launches.

There isn’t anything particularly special about this class, but since it is handy and generic enough to be used in any graphical project (with slight modification), I will reproduce the code here:

public class Glitcher_Utils { public static final String LOG_TAG="glitcher_log"; public static final int V_SHADE=0, F_SHADE=1, S_PROG=2; public static final String SAVE_SHARED_FILENAME="net.dystopiazero.theglitcher.sharedprefs"; public static final String SAVE_LAST_EFFECT="last_effect"; public static final String SAVE_LAST_MODE="last_mode"; public static final String SAVE_LAST_CAM_INDEX="last_cam_index"; public static void savePreference(String tag, String val, Context context) { SharedPreferences prefs=context.getSharedPreferences(SAVE_SHARED_FILENAME,Context.MODE_PRIVATE); SharedPreferences.Editor editor=prefs.edit(); editor.putString(tag, val); editor.commit(); } public static String getPreference(String tag, Context context) { SharedPreferences prefs=context.getSharedPreferences(SAVE_SHARED_FILENAME,Context.MODE_PRIVATE); String val=prefs.getString(tag, "null"); return val; } public static boolean compileShaders(String vertex_shader, String fragment_shader, int[] ids) { if (ids.length<3) { Log.e(LOG_TAG,"Glitcher_Utils,compileShaders: Buffer too small"); return false; } ids[V_SHADE]=GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER); ids[F_SHADE]=GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER); GLES20.glShaderSource(ids[V_SHADE],vertex_shader); GLES20.glShaderSource(ids[F_SHADE],fragment_shader); GLES20.glCompileShader(ids[V_SHADE]); GLES20.glCompileShader(ids[F_SHADE]); int[] info=new int[1]; GLES20.glGetShaderiv(ids[V_SHADE], GLES20.GL_COMPILE_STATUS, info,0); if (info[0]==0) { Log.e(Glitcher_Utils.LOG_TAG,"Glitcher_Utils,compileShaders: Vertex Shader Error: "+GLES20.glGetShaderInfoLog(ids[V_SHADE])); GLES20.glDeleteShader(ids[V_SHADE]); return false; } GLES20.glGetShaderiv(ids[F_SHADE], GLES20.GL_COMPILE_STATUS, info,0); if (info[0]==0) { Log.e(Glitcher_Utils.LOG_TAG,"Glitcher_Utils,compileShaders: Fragment Shader Error: "+GLES20.glGetShaderInfoLog(ids[F_SHADE])); GLES20.glDeleteShader(ids[F_SHADE]); return false; } ids[S_PROG]=GLES20.glCreateProgram(); GLES20.glAttachShader(ids[S_PROG],ids[V_SHADE]); GLES20.glAttachShader(ids[S_PROG],ids[F_SHADE]); GLES20.glLinkProgram(ids[S_PROG]); IntBuffer inf=IntBuffer.wrap(info); GLES20.glGetProgramiv(ids[S_PROG], GLES20.GL_LINK_STATUS, inf); if (info[0]==GLES20.GL_FALSE) { Log.e(Glitcher_Utils.LOG_TAG,"Glitcher_Utils,compileShaders: Shader Program Link Error: "+GLES20.glGetProgramInfoLog(ids[S_PROG])); GLES20.glDeleteProgram(ids[S_PROG]); return false; } return true; } }

The savePreference() and getPreference() methods save and retrieve a String value using Android’s SharedPreferences class, which can be used to save data between application launches. In Glitcher VR, these methods are used to save information about the active filter, active camera, and whether VR mode is enabled on program exit. On program startup, the preferences are retrieved and the previously active effect is selected, the previously active camera is opened, and VR mode is appropriately toggled.

Likewise, the static compileShaders() method compiles a vertex and fragment shader, links them to a shader program, and places their identifiers in an array that is supplied by the caller. This method is called at least once from every filter, and used in other parts of Glitcher VR that require things to be rendered to the screen, such as the notification system. As this method performs a common generic task, it can be plugged into any OpenGL program with minimal modification.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Popular ebooks
Whisky: Malt Whiskies of Scotland (Collins Little Books) by dominic roskrow(56030)
What's Done in Darkness by Kayla Perrin(26593)
The Fifty Shades Trilogy & Grey by E L James(19079)
Shot Through the Heart: DI Grace Fisher 2 by Isabelle Grey(19058)
Shot Through the Heart by Mercy Celeste(18936)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 10 by Isuna Hasekura and Jyuu Ayakura(17112)
Python GUI Applications using PyQt5 : The hands-on guide to build apps with Python by Verdugo Leire(16994)
Peren F. Statistics for Business and Economics...Essential Formulas 3ed 2025 by Unknown(16878)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 03 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(16825)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 01 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(16447)
The Subtle Art of Not Giving a F*ck by Mark Manson(14353)
The 3rd Cycle of the Betrayed Series Collection: Extremely Controversial Historical Thrillers (Betrayed Series Boxed set) by McCray Carolyn(14140)
Stepbrother Stories 2 - 21 Taboo Story Collection (Brother Sister Stepbrother Stepsister Taboo Pseudo Incest Family Virgin Creampie Pregnant Forced Pregnancy Breeding) by Roxi Harding(13645)
Scorched Earth by Nick Kyme(12771)
Drei Generationen auf dem Jakobsweg by Stein Pia(10965)
Suna by Ziefle Pia(10889)
Scythe by Neal Shusterman(10338)
The Ultimate Python Exercise Book: 700 Practical Exercises for Beginners with Quiz Questions by Copy(9541)
International Relations from the Global South; Worlds of Difference; First Edition by Arlene B. Tickner & Karen Smith(9522)
D:\Jan\FTP\HOL\Work\Alien Breed - Tower Assault CD32 Alien Breed II - The Horror Continues Manual 1.jpg by PDFCreator(9515)