OpenGL: Difference between revisions
Levidsmith (talk | contribs) No edit summary |
Levidsmith (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
I am attempting to integrate OpenGL into the code, so that the game uses hardware graphics acceleration. Hopefully, this will improve some of the framerate issues. | I am attempting to integrate OpenGL into the code, so that the game uses hardware graphics acceleration. Hopefully, this will improve some of the framerate issues. | ||
== Get code to compile with a single line of OpenGL == | |||
I can compile a program using #include "SDL_opengl.h", but I am getting errors about missing functions when an OpenGL method is called. | I can compile a program using #include "SDL_opengl.h", but I am getting errors about missing functions when an OpenGL method is called. | ||
Line 17: | Line 20: | ||
gcc test.c `sdl-config --libs --cflags` -lglut32 -lglu32 -lopengl32 | gcc test.c `sdl-config --libs --cflags` -lglut32 -lglu32 -lopengl32 | ||
== Display a bitmap to the screen == | |||
I got a simple square to display in OpenGL: | I got a simple square to display in OpenGL: | ||
Line 38: | Line 43: | ||
[[File:Opengl tux02.jpg|400px]] | [[File:Opengl tux02.jpg|400px]] | ||
Pseudo Code: | |||
INTEGER playerX | |||
INTEGER playerY | |||
INTEGER playerVelocityX | |||
INTEGER playerVelocityY | |||
Setup_SDL | |||
Setup_OpenGL | |||
Load_Bitmaps | |||
GameLoop { | |||
While (User hasn't Quit) { | |||
IF (User presses up) THEN | |||
playerVelocityY = - PLAYER_SPEED | |||
IF (User presses down) THEN | |||
playerVelocityY = PLAYER_SPEED | |||
IF (User presses left) THEN | |||
playerVelocityX = - PLAYER_SPEED | |||
IF (User presses right) THEN | |||
playerVelocityX = PLAYER_SPEED | |||
playerX = playerX + playerVelocityX | |||
playerY = playerY + playerVelocityY | |||
Render_Screen | |||
} | |||
} |
Revision as of 05:17, 13 February 2010
I am attempting to integrate OpenGL into the code, so that the game uses hardware graphics acceleration. Hopefully, this will improve some of the framerate issues.
Get code to compile with a single line of OpenGL
I can compile a program using #include "SDL_opengl.h", but I am getting errors about missing functions when an OpenGL method is called.
I installed the OpenGL libraries in cygwin, so I'm not sure if those were necessary:
Installing these files may help
http://www.libsdl.org/extras/win32/cygwin/
Found out that I was using the wrong parameters to compile. I should have been using this:
gcc test.c `sdl-config --libs --cflags` -lglut32 -lglu32 -lopengl32
Display a bitmap to the screen
I got a simple square to display in OpenGL:
Added Tux:
Tux on an image background:
One of the vertices was off, which made the background skewed.
Moving Block
Next Step is to get the player block moving
Pseudo Code:
INTEGER playerX INTEGER playerY INTEGER playerVelocityX INTEGER playerVelocityY
Setup_SDL Setup_OpenGL Load_Bitmaps
GameLoop {
While (User hasn't Quit) { IF (User presses up) THEN playerVelocityY = - PLAYER_SPEED
IF (User presses down) THEN playerVelocityY = PLAYER_SPEED
IF (User presses left) THEN playerVelocityX = - PLAYER_SPEED
IF (User presses right) THEN playerVelocityX = PLAYER_SPEED
playerX = playerX + playerVelocityX playerY = playerY + playerVelocityY
Render_Screen } }