Positioning elements in 2D space with OpenGL ES

后端 未结 3 2104
盖世英雄少女心
盖世英雄少女心 2021-02-09 06:00

In my spare time I like to play around with game development on the iPhone with OpenGL ES. I\'m throwing together a small 2D side-scroller demo for fun, and I\'m relatively new

3条回答
  •  清歌不尽
    2021-02-09 06:19

    If you are only using screen aligned quads it might be easier to use the OES Draw Texture extension. Then you can use a single texture to hold all your game "sprites". First specify the crop rectangle by setting the GL_TEXTURE_CROP_RECT_OES TexParameter. This is the boundry of the sprite within the larger texture. To render, call glDrawTexiOES passing in the desired position & size in viewport coordinates.

    int rect[4] = {0, 0, 16, 16};
    glBindTexture(GL_TEXTURE_2D, sprites);
    glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, rect);
    glDrawTexiOES(x, y, z, width, height);
    

    This extension isn't available on all devices, but it works great on the iPhone.

提交回复
热议问题