Skip to main content

using opengl texture coordinates



From my understanding the texture coordinates are s,t and go from 0,0 to 1,1. So if you wanted half the texture you would use .5 instead of 1. No matter what I do I get the whole texture so let me show what I have and attach the png texture. How do I map the first half of the texture to the quad? Thanks for any help





!test image that has 4 sub images - http://www.sendspace.com/file/6b5y7x







///Main activity thread:

public void onSurfaceCreated(GL10 gl, EGLConfig config) {

myquad.loadGLTexture(gl, this.context);



gl.glEnable(GL10.GL_BLEND);

gl.glBlendFunc(gl.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glEnable(GL10.GL_TEXTURE_2D);

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);

gl.glDisable(GL10.GL_DEPTH_TEST);



x=y=0;

}



public void onSurfaceChanged(GL10 gl, int w, int h) {

width=w;

height=h;

gl.glViewport(0, 0, w, h);

gl.glMatrixMode(GL10.GL_PROJECTION); //Select The Projection Matrix

gl.glLoadIdentity();

gl.glOrthof(0.0f, 640f, 0.0f, 480.0f, -1.0f, 1.0f);

}



CLASS QUAD{

private float vertices[] = {

0.0f, 0.0f, 0.0f, // 0. top left

1.0f, 0.0f, 0.0f, // 1. top right

0.0f, 1.0f, 0.0f, // 2. bottom left

1.0f, 1.0f, 0.0f // bottom right

};



private float texture[] = {

0.0f, 0.0f,

.5f, 0.0f,

0.0f, 0.5f,

0.5f, 0.5f

};



public void loadGLTexture(GL10 gl, Context context) {

Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),

R.drawable.herowalkback);

Matrix flip = new Matrix();

flip.postScale(1f,-1f);

Bitmap bmp=Bitmap.createBitmap(bitmap, 0, 0,

bitmap.getWidth(),

bitmap.getHeight(), flip, false);



if (bitmap == null)

{

Log.i ("info", "bitmap could not be decoded");

}

gl.glGenTextures(1, textures, 0);

gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);



//Create Nearest Filtered Texture

gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);

gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);



gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);

gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);



gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_REPLACE);



GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0,bitmap, 0);



public void Draw(GL10 gl)

{

// set the color for the triangle

gl.glColor4f(0.0f, 1.0f, 0.0f, 0.5f);



gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texturebuffer);

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexbuffer);



gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);



}







} ////end class quad







//GLsurfaceview main thread

public void onDrawFrame(GL10 gl) {

startframe=SystemClock.elapsedRealtime();



gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

gl.glLoadIdentity();

myquad.Draw(gl);

}




Comments

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.