CS185c
Chris Pollett
Nov. 9, 2009
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);