开发者

How to use libpng with OpenGL for a 2D game?

I am beginning with OpenGL, and I want to make a very simple game with airplanes. Now I have a PNG of an airplane seen from above, and I want to draw this on the screen. Currently I only know how to draw triangles that rotate:

float angle = 0.0f;
void renderScene(void) {
  glClear(GL_COLOR_BUFFER_BIT);
  glPushMatrix();开发者_如何学JAVA
  glRotatef(angle, 0.0f, 0.0f, 1.0f);
  glBegin(GL_TRIANGLES);
  glVertex2f(-0.5,-0.5);
  glVertex2f(0.5,0.0);
  glVertex2f(0.0,0.5);
  glEnd();
  glPopMatrix();
  glutSwapBuffers();
  angle += 0.1;
}

Can anyone help me? Thanks.


This is your stash of secrets: http://nehe.gamedev.net/

By the way you will end up drawing a quad (or a triangle strip) and applying the texture onto the polygon, nothing so complicated.. but start in a precise way by looking at tutorials and understanding how OpenGL works, it would be better.

This book will be better than Nehe (since it's tailored exactly for OpenGL ES): http://opengles-book.com/


Instead of using libpng directly, you might want to consider using DevIL. It's intended specifically for the kind of job you seem to be trying to do so it'll generally make it quite a bit easier to do (and next month, when somebody decides you should display a JPEG or maybe a TIFF instead of a PNG, it'll handle that without any major rewrite either).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜