This draws a portion of a texture, stretched to the width and height. This monster method draws a portion of a texture, stretched to the width and height, scaled and rotated around an origin, and optionally flipped. Int srcX, int srcY, int srcWidth, int srcHeight, Int srcWidth, int srcHeight, boolean flipX, boolean flipY)ĭraws a portion of a texture, stretched to the width and height, and optionally flipped.įloat originX, float originY, float width, float height,įloat scaleX, float scaleY, float rotation, Int srcX, int srcY, int srcWidth, int srcHeight)įloat width, float height, int srcX, int srcY, SpriteBatch has many methods for drawing a texture: Method signatureĭraws the texture using the texture’s width and height The texture will be drawn in a rectangle positioned at 10,10 with a width and height equal to the size of the texture. Here a texture is created and passed to a SpriteBatch to be drawn. Using SpriteBatch (source) in an application looks like this: For these reasons, it is common to store many smaller images in a larger image and then draw regions of the larger image to both maximize geometry batching and avoid texture changes. Also, binding a texture is a somewhat expensive operation. If it is given a texture different than the last texture, then it binds the last texture, submits the collected geometry to be drawn, and begins collecting geometry for the new texture.Ĭhanging textures every few rectangles that are drawn prevents SpriteBatch from batching much geometry. It collects the geometry without submitting it to the GPU. SpriteBatch is given a texture and coordinates for each rectangle to be drawn. Instead, many rectangles for the same texture can be described and sent to the GPU all at once. It would be inefficient to send each rectangle one at a time to the GPU to be drawn. It is also very common to draw the same texture or various regions of that texture many times. It is very common to draw a texture mapped to rectangular geometry. This means that the geometry is specified in pixels, which makes it easy to draw textures in the appropriate size and position on the screen. Many 2D games configure the viewport to match the screen resolution. The size and position on the screen that the texture is drawn is determined by both the geometry and how the OpenGL viewport is configured. To do the actual drawing, first the texture is bound (i.e., made the current texture), then the geometry is given to OpenGL to draw. A rectangle that is a subset of a texture is called a texture region. For example, the geometry could be a rectangle and the texture could be applied so that each corner of the rectangle corresponds to a corner of the texture. ![]() To draw a texture, geometry is described and the texture is applied by specifying where each vertex in the geometry corresponds on the texture. Drawing imagesĪn image that has been decoded from its original format (e.g., PNG) and uploaded to the GPU is called a texture. ![]() This page gives a brief overview of how images are drawn using OpenGL and how libGDX simplifies and optimizes the task through the SpriteBatch class.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |