Hi all,
I have figured out how to use glDrawElements to render quads from an interleaved array of vertices to draw an internal video buffer of pixels at various sizes to the screen (see code below):
Since I want to see if I can port this to Android, I need to use triangles instead of quads (is deprecated now...), but I just can't figure out how to place the vertices in the vertex array to draw triangles properly...Code:procedure TApplication.RenderScreen;type TVertex = packed record x,y,z : Single; col : TRGBA; end; var col : TRGBA; buff : PVideoBuffer; palette : TChip16Palette; sx,sy : Integer; dx,dy : Integer; Vertices : array[0..(cVideoPixelCount * 4) - 1] of TVertex; // 4 x vertices per screen pixel (maximum possible per screen...) Indices : array[0..(cVideoPixelCount * 4) - 1] of GLuint; // 4 x vertices per screen pixel (maximum possible per screen...) VPointer : PByte; // vertices pointer CPointer : PByte; // color pointer VertexCount : Integer; begin palette := FChip16.Palette; col := palette[FChip16.BGColor]; glClearColor(col.r/255,col.g/255,col.b/255,col.a/255); glClear(GL_COLOR_BUFFER_BIT); glDisable(GL_BLEND); // draw video buffer to screen buff := FChip16.VideoBuffer; // enable and specify pointers to vertex arrays glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); VPointer := @Vertices[0]; CPointer := @Vertices[0]; Inc(CPointer,3 * SizeOf(GLfloat)); glVertexPointer(3, GL_FLOAT , SizeOf(TVertex), VPointer); glColorPointer (4, GL_UNSIGNED_BYTE, SizeOf(TVertex), CPointer); VertexCount := 0; dy := 0; for sy := 0 to cVideoResY - 1 do begin dx := 0; for sx := 0 to cVideoResX - 1 do begin col := palette[buff^[sy,sx]]; if buff^[sy,sx] <> cTransparentColor then begin Vertices[VertexCount].col := col; Vertices[VertexCount].x := dx; Vertices[VertexCount].y := dy; Indices[VertexCount] := VertexCount; Inc(VertexCount); Vertices[VertexCount].col := col; Vertices[VertexCount].x := dx+FScale; Vertices[VertexCount].y := dy; Indices[VertexCount] := VertexCount; Inc(VertexCount); Vertices[VertexCount].col := col; Vertices[VertexCount].x := dx+FScale; Vertices[VertexCount].y := dy+FScale; Indices[VertexCount] := VertexCount; Inc(VertexCount); Vertices[VertexCount].col := col; Vertices[VertexCount].x := dx; Vertices[VertexCount].y := dy+FScale; Indices[VertexCount] := VertexCount; Inc(VertexCount); end; Inc(dx,FScale); end; Inc(dy,FScale); end; // draw number of elements glDrawElements(GL_QUADS, VertexCount, GL_UNSIGNED_INT,@Indices); glDisableClientState(GL_VERTEX_ARRAY); // disable vertex arrays glDisableClientState(GL_COLOR_ARRAY); end;
My screen is orientated with (0,0) at top left, and using Clockwise winding for triangles, quads, etc.
Any ideas?
cheers,
Paul



Reply With Quote


Hopefully it's fixed now though, is rather nasty issue to deal with.
