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

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex