# HG changeset patch # User unc0rr # Date 1237842574 0 # Node ID 9c3d0e3df6bb56ad2b4ebce111e74ad2e7d2b509 # Parent c357f5b55320aa9c7fb873d6795efc9b8415b026 patch by koda: - Finish convertion to OpenGL ES diff -r c357f5b55320 -r 9c3d0e3df6bb hedgewars/SDLh.pas --- a/hedgewars/SDLh.pas Mon Mar 23 19:03:51 2009 +0000 +++ b/hedgewars/SDLh.pas Mon Mar 23 21:09:34 2009 +0000 @@ -36,6 +36,7 @@ {$PACKRECORDS C} {$IFDEF DARWIN} +{$IFNDEF IPHONE} {$linklib libpng} {$linklib libz} {$linklib libjpeg} @@ -53,6 +54,7 @@ {$linkframework IOKit} {add ForceFeedback and CoreAudio frameworks when you use SDL-1.3} {$ENDIF} +{$ENDIF} (* SDL *) const {$IFDEF WIN32} @@ -61,11 +63,15 @@ {$IFDEF UNIX} {$IFDEF DARWIN} SDLLibName = 'libSDL.a'; +{$IFNDEF IPHONE} {$linklib libSDL} {$linklib SDLmain} {$linkframework Cocoa} +{$ENDIF} {$PASCALMAINNAME SDL_main} +{$IFNDEF IPHONE} {$linklib gcc} +{$ENDIF} {$ELSE} SDLLibName = 'libSDL.so'; {$ENDIF} @@ -297,7 +303,9 @@ {$IFDEF UNIX} {$IFDEF DARWIN} SDL_TTFLibName = 'libSDL_ttf.a'; +{$IFNDEF IPHONE} {$linklib libSDL_ttf} +{$ENDIF} {$ELSE} SDL_TTFLibName = 'libSDL_ttf.so'; {$ENDIF} @@ -332,7 +340,9 @@ {$IFDEF UNIX} {$IFDEF DARWIN} SDL_MixerLibName = 'libSDL_mixer.a'; +{$IFNDEF IPHONE} {$linklib libSDL_mixer} +{$ENDIF} {$ELSE} SDL_MixerLibName = 'libSDL_mixer.so'; {$ENDIF} @@ -398,7 +408,9 @@ {$IFDEF UNIX} {$IFDEF DARWIN} SDL_ImageLibName = 'libSDL_image.a'; +{$IFNDEF IPHONE} {$linklib libSDL_image} +{$ENDIF} {$ELSE} SDL_ImageLibName = 'libSDL_image.so'; {$ENDIF} @@ -414,7 +426,9 @@ {$IFDEF UNIX} {$IFDEF DARWIN} SDL_NetLibName = 'libSDL_net.a'; +{$IFNDEF IPHONE} {$linklib libSDL_net} +{$ENDIF} {$ELSE} SDL_NetLibName = 'libSDL_net.so'; {$ENDIF} diff -r c357f5b55320 -r 9c3d0e3df6bb hedgewars/uMisc.pas --- a/hedgewars/uMisc.pas Mon Mar 23 19:03:51 2009 +0000 +++ b/hedgewars/uMisc.pas Mon Mar 23 21:09:34 2009 +0000 @@ -497,7 +497,11 @@ size:= cScreenWidth * cScreenHeight * 3; p:= GetMem(size); +{$IFDEF IPHONE} +//since opengl es operates on a single surface GL_FRONT is implied, but how to test that? +{$ELSE} glReadBuffer(GL_FRONT); +{$ENDIF} glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_BGR, GL_UNSIGNED_BYTE, p); {$I-} diff -r c357f5b55320 -r 9c3d0e3df6bb hedgewars/uStore.pas --- a/hedgewars/uStore.pas Mon Mar 23 19:03:51 2009 +0000 +++ b/hedgewars/uStore.pas Mon Mar 23 21:09:34 2009 +0000 @@ -316,6 +316,7 @@ procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); var rr: TSDL_Rect; _l, _r, _t, _b: real; + VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; begin if SourceTexture^.h = 0 then exit; rr.x:= X; @@ -330,21 +331,33 @@ glBindTexture(GL_TEXTURE_2D, SourceTexture^.id); -glBegin(GL_QUADS); - -glTexCoord2f(_l, _t); -glVertex2i(X, Y); - -glTexCoord2f(_r, _t); -glVertex2i(rr.w + X, Y); +VertexBuffer[0].X:= X; +VertexBuffer[0].Y:= Y; +VertexBuffer[1].X:= rr.w + X; +VertexBuffer[1].Y:= Y; +VertexBuffer[2].X:= rr.w + X; +VertexBuffer[2].Y:= rr.h + Y; +VertexBuffer[3].X:= X; +VertexBuffer[3].Y:= rr.h + Y; -glTexCoord2f(_r, _b); -glVertex2i(rr.w + X, rr.h + Y); +TextureBuffer[0].X:= _l; +TextureBuffer[0].Y:= _t; +TextureBuffer[1].X:= _r; +TextureBuffer[1].Y:= _t; +TextureBuffer[2].X:= _r; +TextureBuffer[2].Y:= _b; +TextureBuffer[3].X:= _l; +TextureBuffer[3].Y:= _b; -glTexCoord2f(_l, _b); -glVertex2i(X, rr.h + Y); +glEnableClientState(GL_VERTEX_ARRAY); +glEnableClientState(GL_TEXTURE_COORD_ARRAY); -glEnd() +glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); +glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); +glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); + +glDisableClientState(GL_TEXTURE_COORD_ARRAY); +glDisableClientState(GL_VERTEX_ARRAY) end; procedure DrawTexture(X, Y: LongInt; Texture: PTexture); @@ -370,6 +383,7 @@ procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, Frames: LongInt); var ft, fb: GLfloat; hw: LongInt; + VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; begin glPushMatrix; glTranslatef(X, Y, 0); @@ -385,21 +399,34 @@ glBindTexture(GL_TEXTURE_2D, Texture^.id); -glBegin(GL_QUADS); - -glTexCoord2f(0, ft); -glVertex2i(-hw, -16); - -glTexCoord2f(Texture^.rx, ft); -glVertex2i(hw, -16); +VertexBuffer[0].X:= -hw; +VertexBuffer[0].Y:= -16; +VertexBuffer[1].X:= hw; +VertexBuffer[1].Y:= -16; +VertexBuffer[2].X:= hw; +VertexBuffer[2].Y:= 16; +VertexBuffer[3].X:= -hw; +VertexBuffer[3].Y:= 16; -glTexCoord2f(Texture^.rx, fb); -glVertex2i(hw, 16); +TextureBuffer[0].X:= 0; +TextureBuffer[0].Y:= ft; +TextureBuffer[1].X:= Texture^.rx; +TextureBuffer[1].Y:= ft; +TextureBuffer[2].X:= Texture^.rx; +TextureBuffer[2].Y:= fb; +TextureBuffer[3].X:= 0; +TextureBuffer[3].Y:= fb; -glTexCoord2f(0, fb); -glVertex2i(-hw, 16); +glEnableClientState(GL_VERTEX_ARRAY); +glEnableClientState(GL_TEXTURE_COORD_ARRAY); -glEnd(); +glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); +glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); +glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); + +glDisableClientState(GL_TEXTURE_COORD_ARRAY); +glDisableClientState(GL_VERTEX_ARRAY); + glPopMatrix end; @@ -426,6 +453,7 @@ end; procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); +var VertexBuffer: array [0..3] of TVertex2f; begin glPushMatrix; glTranslatef(X, Y, 0); @@ -440,21 +468,24 @@ glBindTexture(GL_TEXTURE_2D, Tex^.id); -glBegin(GL_QUADS); - -glTexCoord2f(0, 0); -glVertex2i(-hw, -hh); - -glTexCoord2f(Tex^.rx, 0); -glVertex2i(hw, -hh); +VertexBuffer[0].X:= -hw; +VertexBuffer[0].Y:= -hh; +VertexBuffer[1].X:= hw; +VertexBuffer[1].Y:= -hh; +VertexBuffer[2].X:= hw; +VertexBuffer[2].Y:= hh; +VertexBuffer[3].X:= -hw; +VertexBuffer[3].Y:= hh; -glTexCoord2f(Tex^.rx, Tex^.ry); -glVertex2i(hw, hh); +glEnableClientState(GL_VERTEX_ARRAY); +glEnableClientState(GL_TEXTURE_COORD_ARRAY); -glTexCoord2f(0, Tex^.ry); -glVertex2i(-hw, hh); +glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); +glTexCoordPointer(2, GL_FLOAT, 0, @Tex^.tb); +glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); -glEnd(); +glDisableClientState(GL_TEXTURE_COORD_ARRAY); +glDisableClientState(GL_VERTEX_ARRAY); glPopMatrix end; @@ -502,7 +533,13 @@ end; procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); +const VertexBuffer: array [0..3] of TVertex2f = ( + (x: -16; y: -16), + (x: 16; y: -16), + (x: 16; y: 16), + (x: -16; y: 16)); var l, r, t, b: real; + TextureBuffer: array [0..3] of TVertex2f; begin t:= Pos * 32 / HHTexture^.h; @@ -525,41 +562,51 @@ glBindTexture(GL_TEXTURE_2D, HHTexture^.id); -glBegin(GL_QUADS); - -glTexCoord2f(l, t); -glVertex2i(-16, -16); +TextureBuffer[0].X:= l; +TextureBuffer[0].Y:= t; +TextureBuffer[1].X:= r; +TextureBuffer[1].Y:= t; +TextureBuffer[2].X:= r; +TextureBuffer[2].Y:= b; +TextureBuffer[3].X:= l; +TextureBuffer[3].Y:= b; -glTexCoord2f(r, t); -glVertex2i(16, -16); +glEnableClientState(GL_VERTEX_ARRAY); +glEnableClientState(GL_TEXTURE_COORD_ARRAY); -glTexCoord2f(r, b); -glVertex2i(16, 16); +glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); +glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); +glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); -glTexCoord2f(l, b); -glVertex2i(-16, 16); +glDisableClientState(GL_TEXTURE_COORD_ARRAY); +glDisableClientState(GL_VERTEX_ARRAY); -glEnd(); glColor4f(1,1,1,1); glPopMatrix end; procedure DrawFillRect(r: TSDL_Rect); +var VertexBuffer: array [0..3] of TVertex2f; begin glDisable(GL_TEXTURE_2D); glColor4ub(0, 0, 0, 127); -glBegin(GL_QUADS); +VertexBuffer[0].X:= r.x; +VertexBuffer[0].Y:= r.y; +VertexBuffer[1].X:= r.x + r.w; +VertexBuffer[1].Y:= r.y; +VertexBuffer[2].X:= r.x + r.w; +VertexBuffer[2].Y:= r.y + r.h; +VertexBuffer[3].X:= r.x; +VertexBuffer[3].Y:= r.y + r.h; -glVertex2i(r.x , r.y ); -glVertex2i(r.x + r.w , r.y ); -glVertex2i(r.x + r.w , r.y + r.h); -glVertex2i(r.x , r.y + r.h); - -glEnd(); +glEnableClientState(GL_VERTEX_ARRAY); +glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); +glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); +glDisableClientState(GL_VERTEX_ARRAY); glColor4f(1, 1, 1, 1); glEnable(GL_TEXTURE_2D)