How To Display A Scaled Down Gl Es Texture Without Clamp Or Repeat On Android
Solution 1:
The repeated image chunks look like GPU tiling artifacts, not texture repeating. Add a glClear()
call to erase the background.
Solution 2:
It would seem what you are looking for is a "fit" system to get the correct frame of your element. It would mean for instance you are having a 100x200
image and you want to display it in a frame of 50x50
. The result should then be seeing the whole image in rectangle (25, 0, 25, 50)
. So the resulting frame must respect the image ratio (25/50 = 100/200
) and original frame boundaries must be respected.
To achieve this generally you need to compare the image ratio and the target frame ratio: imageRatio = imageWidth/imageHeight
and frameRatio = frameWidth/frameHeight
. Then if image ratio is larger then the frame ratio it means you need black borders on top and bottom while if the frame ratio is larger then you will see black borders on left and right side.
So to compute the target frame:
imageRatio = imageWidth/imageHeight
frameRatio = frameWidth/frameHeight
if(imageRatio > frameRatio) {
targetFrame = {0, (frameHeight-frameWidth/imageRatio)*.5, frameWidth, frameWidth/imageRatio} // frame as: {x, y, width, height}
}
else {
targetFrame = {(frameWidth-frameHeight*imageRatio)*.5, 0, frameHeight*imageRatio, frameHeight} // frame as: {x, y, width, height}
}
In your case the image width and height are the ones received from the stream; frame width and height are from your target frame which seems to be a result from matrices but for full screen case that would simply be values from glOrtho if you use it. The target frame should then be used to construct the vertices positions so you get exactly correct vertex data to display the full texture.
I see you use matrices to do all the computation in your case and the same algorithm may be used to be converted to matrix but I discourage you to do so. You seem to be over-abusing matrices which makes your code completely unmaintainable. I suggest in your case you keep to "ortho" projection matrix, use frames to draw textures and only use matrix scale and translations where it makes sense to do so.
Post a Comment for "How To Display A Scaled Down Gl Es Texture Without Clamp Or Repeat On Android"