CS185c
Chris Pollett
Nov. 8, 2010
float lightAmbient[] = new float[]{ 0.2f, 0.2f, 0.2f, 1};
float lightDiffuse[] = new float[]{ 1, 1, 1, 1};
float[] lightPos = new float[] {1, 1, 1, 1};
gl.glEnable(GL10.GL_LIGHTING);
gl.glEnable(GL10.GL_LIGHT0);
gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, lightAmbient, 0);
gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, lightDiffuse, 0);
gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, lightPos, 0);
float matAmbient[] = new float[]{1, 1, 1, 1};
float matDiffuse[] = new float[]{1, 1, 1, 1};
gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, matAmbient, 0);
gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, matDiffuse, 0);
private long startTime;
startTime = System.currentTimeMillis();
long elapsed = System.currentTimeMillis() - startTime; gl.glRotatef(elapsed*(30f/1000f), 0, 1, 0); gl.glRotatef(elapsed*(15f/1000f), 1, 0, 0);
Which of the following statements is true:
private final IntBuffer mTextureBuffer;used to store our texture info.
int texCoords[] = {
//Front
0, one, one, one, 0, 0, one, 0,
//Back
one, one, one, 0, 0, one, 0, 0,
//Left
one, one, one, 0, 0, one, 0, 0,
//Right
one, one, one, 0, 0, one, 0, 0,
//Top
one, 0, 0, 0, one, one, 0, one,
//Bottom
0, 0, 0, one, one, 0, one, one
};
ByteBuffer tbb = ByteBuffer.allocateDirect(texCoords.length * 4);
tbb.order(ByteOrder.nativeOrder());
mTextureBuffer = tbb.asIntBuffer();
mTextureBuffer.put(texCoords);
mTextureBuffer.position(0);
static void loadTexture(GL10 gl, Context context, int resource)
{
Bitmap bmp = BitmapFactory.decodeResource(
context.getResources(), resource);
ByteBuffer bb = extract(bmp);
load(gl, bb, bmp.getWidth(), bmp.getHeight());
}
static ByteBuffer extract(Bitmap bmp)
{
ByteBuffer bb = ByteBuffer.allocateDirect(bmp.getHeight() * bmp.getWidth() * 4);
bb.order(ByteOrder.BIG_ENDIAN);
IntBuffer ib = bb.asIntBuffer();
// Convert ARGB ->RGBA
for(int y = bmp.getHeight() - 1; y > -1; y--)
{
for(int x =0; x < bmp.getWidth(); x++)
{
int pix = bmp.getPixel(x, bmp.getHeight() -y - 1);
int alpha = ((pix >>24) & 0xFF);
int red = ((pix >> 16) & 0xFF);
int green = ((pix >> 8) & 0xFF);
int blue = ((pix) & 0xFF);
ib.put(red << 24 | green << 16 | blue << 8 | alpha);
}
}
bb.position(0);
return bb;
}
static void load(GL10 gl, ByteBuffer bb, int width, int height)
{
int[] tmp_tex = new int[1];
gl.glGenTextures(1, tmp_tex, 0);
int tex = tmp_tex[0];
//Load it up
gl.glBindTexture(GL10.GL_TEXTURE_2D, tex);
gl.glTexImage2D(GL10.GL_TEXTURE_2D, 0, GL10.GL_RGBA,
width, height, 0, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, bb);
gl.glTexParameterx(GL10.GL_TEXTURE_2D,
GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
gl.glTexParameterx(GL10.GL_TEXTURE_2D,
GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
}
gl.glTexCoordPointer(2, GL10.GL_FIXED, 0, mTextureBuffer);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glEnable(GL10.GL_TEXTURE_2D); GLCube.loadTexture(gl, view.getContext(), R.drawable.myphoto);
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
LinearLayout ll= new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
Button button = new Button(this);
button.setText("hello");
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Here is an alert")
.setCancelable(true);
alertDialog = builder.create();
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
} });
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
alertDialog.show();
}
});
ll.addView(button);
GLView glview = new GLView(this);
ll.addView(glview);
setContentView(ll);
}
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION" />
telnet localhost 5554
geo fix -10.5 23.4
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
protected void onResume()
{
/*
* Add LocationListener and request updates every 1000ms or 10m
* Notice in this case we are saying this Activity implements LocationListener
*/
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 1000, 10f, this);
super.onResume();
}
protected void onPause()
{
locationManager.removeUpdates(this);
super.onPause();
}
public void onProviderDisabled(String provider)
{
Log.v("GPS", "Disabled");
Intent intent = new Intent(
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
public void onProviderEnabled(String provider)
{
Log.v("GPS", "Enabled");
}
public void onStatusChanged(String provider, int status, Bundle extras)
{
switch (status)
{
case LocationProvider.OUT_OF_SERVICE:
Log.v("GPS", "Status Changed: Out of Service");
break;
case LocationProvider.TEMPORARILY_UNAVAILABLE:
Log.v("GPS", "Status Changed: Temporarily Unavailable");
break;
case LocationProvider.AVAILABLE:
Log.v("GPS", "Status Changed: Available");
break;
}
}