Can you explain me how to achieve my needs with your scale tactic? i can't figure how to do it
code examples are welcome thanks ! On Nov 2, 2:40 pm, Latimerius <[email protected]> wrote: > If all you need is to zoom a quad why don't you just glScale() it? > > Moving the quad along the z axis will sure work but it seems like the > hard way to achieve this. Sure, scaling and moving along z will not > get you the *exactly* same result, however I doubt anybody could > appreciate the slight differences between a bilinear filter and > (generally) tiny perspective distortion, given your geometry is not > quite hi-res. :-) > > > > > > > > On Wed, Nov 2, 2011 at 1:42 PM, saex <[email protected]> wrote: > > I need to show a square polygon with the 100% of the width of the > > screen, then, i supose that i must zoom it (with Z axis) until the > > polygon borders are tounching the screen borders. > > > I'm trying to achieve this using gluProject to project a coordinate in > > 3D into a 2D screen coordinate. If the screen coordinate is either 0 > > or matches the width or height, then it is touching a screen border. > > > The problem is that something is going wrong, the `outputCoords` array > > returned with gluProject is giving me these values: 0,0,0.5, but my > > square is centered on the sreen, and with Z=-5.0f!!!! > > > I dont understand these values... > > > This is the code i'm using to obtain the 2D Projection of my square > > poligon on the screen: > > > /////////////// NEW CODE FOR SCALING THE AR IMAGE TO THE DESIRED > > WIDTH ///////////////// > > > mg.getCurrentModelView(gl); > > mg.getCurrentProjection(gl); > > > float [] modelMatrix = new float[16]; > > float [] projMatrix = new float[16]; > > modelMatrix=mg.mModelView; > > projMatrix=mg.mProjection; > > int [] mView = new int[4]; > > // Fill this with your window width and height > > mView[0] = 0; > > mView[1] = 0; > > mView[2] = 800; //width > > mView[3] = 480; //height > > // Make sure you have 3 components in this array even if the > > screen only needs 2 > > float [] outputCoords = new float[3]; > > // objX, objY, objZ are the coordinates of one of the borders > > GLU.gluProject(-1.0f, -1.0f, 0.0f, modelMatrix, 0, > > projMatrix, 0, mView, 0, outputCoords, 0); > > > This is my square class: > > > public class Square { > > //Buffer de vertices > > private FloatBuffer vertexBuffer; > > //Buffer de coordenadas de texturas > > private FloatBuffer textureBuffer; > > //Puntero de texturas > > private int[] textures = new int[3]; > > //El item a representar > > private Bitmap image; > > //Definición de vertices > > > private float vertices[] = > > { > > -1.0f, -1.0f, 0.0f, //Bottom Left > > 1.0f, -1.0f, 0.0f, //Bottom Right > > -1.0f, 1.0f, 0.0f, //Top Left > > 1.0f, 1.0f, 0.0f //Top Right > > }; > > > private float texture[] = > > { > > //Mapping coordinates for the vertices > > 0.0f, 1.0f, > > 1.0f, 1.0f, > > 0.0f, 0.0f, > > 1.0f, 0.0f > > }; > > //Inicializamos los buffers > > public Square(Bitmap image) { > > ByteBuffer byteBuf = > > ByteBuffer.allocateDirect(vertices.length * 4); > > byteBuf.order(ByteOrder.nativeOrder()); > > vertexBuffer = byteBuf.asFloatBuffer(); > > vertexBuffer.put(vertices); > > vertexBuffer.position(0); > > > byteBuf = ByteBuffer.allocateDirect(texture.length * 4); > > byteBuf.order(ByteOrder.nativeOrder()); > > textureBuffer = byteBuf.asFloatBuffer(); > > textureBuffer.put(texture); > > textureBuffer.position(0); > > > this.image=image; > > } > > //Funcion de dibujado > > public void draw(GL10 gl) { > > gl.glFrontFace(GL10.GL_CCW); > > //gl.glEnable(GL10.GL_BLEND); > > //Bind our only previously generated texture in this case > > gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]); > > //Point to our vertex buffer > > gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer); > > gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer); > > //Enable vertex buffer > > gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); > > gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); > > //Draw the vertices as triangle strip > > gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / > > 3); > > //Disable the client state before leaving > > gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); > > gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); > > //gl.glDisable(GL10.GL_BLEND); > > } > > //Carga de texturas > > public void loadGLTexture(GL10 gl, Context context) { > > //Generamos un puntero de texturas > > gl.glGenTextures(1, textures, 0); > > //y se lo asignamos a nuestro array > > gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]); > > //Creamos filtros de texturas > > 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); > > //Diferentes parametros de textura posibles > > GL10.GL_CLAMP_TO_EDGE > > gl.glTexParameterf(GL10.GL_TEXTURE_2D, > > GL10.GL_TEXTURE_WRAP_S, > > GL10.GL_REPEAT); > > gl.glTexParameterf(GL10.GL_TEXTURE_2D, > > GL10.GL_TEXTURE_WRAP_T, > > GL10.GL_REPEAT); > > /* > > String imagePath = "radiocd5.png"; > > AssetManager mngr = context.getAssets(); > > InputStream is=null; > > try { > > is = mngr.open(imagePath); > > } catch (IOException e1) { e1.printStackTrace(); } > > */ > > //Get the texture from the Android resource directory > > InputStream is=null; > > /* > > if (item.equals("rim")) > > is = > > context.getResources().openRawResource(R.drawable.rueda); > > else if (item.equals("selector")) > > is = > > context.getResources().openRawResource(R.drawable.selector); > > */ > > /* > > is = context.getResources().openRawResource(resourceId); > > Bitmap bitmap = null; > > try { > > bitmap = BitmapFactory.decodeStream(is); > > } finally { > > try { > > is.close(); > > is = null; > > } catch (IOException e) { > > } > > } > > */ > > Bitmap bitmap =image; > > //con el siguiente código redimensionamos las imágenes que > > sean mas > > grandes de 256x256. > > int newW=bitmap.getWidth(); > > int newH=bitmap.getHeight(); > > float fact; > > if (newH>256 || newW>256) > > { > > if (newH>256) > > { > > fact=(float)255/(float)newH; //porcentaje > > por el que multiplicar > > para ser tamaño 256 > > newH=(int)(newH*fact); //altura reducida al > > porcentaje necesario > > newW=(int)(newW*fact); //anchura reducida al > > porcentaje necesario > > } > > if (newW>256) > > { > > fact=(float)255/(float)newW; //porcentaje > > por el que multiplicar > > para ser tamaño 256 > > newH=(int)(newH*fact); //altura reducida al > > porcentaje necesario > > newW=(int)(newW*fact); //anchura reducida al > > porcentaje necesario > > } > > bitmap=Bitmap.createScaledBitmap(bitmap, newW, newH, > > true); > > } > > //con el siguiente código transformamos imágenes no potencia > > de 2 en > > imágenes potencia de 2 (pot) > > //meto el bitmap NOPOT en un bitmap POT para que no aparezcan > > texturas blancas. > > int nextPot=256; > > int h = bitmap.getHeight(); > > int w = bitmap.getWidth(); > > int offx=(nextPot-w)/2; //distancia respecto a la izquierda, > > para > > que la imagen quede centrada en la nueva imagen POT > > int offy=(nextPot-h)/2; //distancia respecto a arriba, para > > que la > > imagen quede centrada en la nueva imagen POT > > Bitmap bitmap2 = Bitmap.createBitmap(nextPot, nextPot, > > Bitmap.Config.ARGB_8888); //crea un bitmap > > ... > > read more » -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

