DGL
https://delphigl.com/forum/

Just Beginning
https://delphigl.com/forum/viewtopic.php?f=19&t=10769
Seite 2 von 2

Autor:  damadmax [ Mi Feb 27, 2013 00:36 ]
Betreff des Beitrags:  Re: Just Beginning

try
Code:
  1. glVertexPointer(2, GL_INT, 0, @GridBufferX);

instead of
Code:
  1. glVertexPointer(4, GL_INT, 0, @GridBufferX);

if you provide just x and y in the array.

i think z will be treated as 0, if not provided

Autor:  NoDPI [ Mi Feb 27, 2013 12:27 ]
Betreff des Beitrags:  Re: Just Beginning

Fixed.. It was not my original question in as much as I was hoping to use something like glGenBuffers but in the case of glVertexArrays for a 'sanity' check I tried glBegin(GL_LINES)|glEnd just to see that my data was constructed correctly. Then I wondered if my 'pointer' was pointing to anything meaningful, it might as well have been the printer port for all I knew..

DaMadMax is right about the 'pointer indexing'...

Code:
  1. glVertexPointer(2, GL_INT, 0, @GridBufferX);


2 for X|Y coordinates. I assume GL_LINES tells the graphics card to step through these in pairs.. As it turns out it was down to the way I referenced the array using @GridBufferX as the pointer,

http://wiki.freepascal.org/OpenGL_Tutorial

I should use,

Code:
  1. glVertexPointer(2, GL_INT, 0, @GridBufferX[0]);


to reference the first element of the array and doing that gives,

Bild

I see the point from StucUK about 2D versus 3D but I think the initialisation tells the card that it is working on 2D data and it adjusts accordingly. Textures... I'll probably have to use them sometime although I feel they may turn out to be overly complex for this particular requirement. To hard for me to get my head around.

Having said that it would be nice to draw the Grid once and then store it as a texture and load that back in rather than repeatedly draw the Grid and overlay the Cursor on top, if that makes sense.

I'll code this back into the original and see what, if any, improvement it gives.

Thanks for the help and your patience.

Autor:  Stucuk [ Mi Feb 27, 2013 15:19 ]
Betreff des Beitrags:  Re: Just Beginning

Yeh i wasn't thinking. The glVertexPointer's have a parameter to specify how many "elements" there are. A texture for the grid isn't all that hard to implement. You just draw a Square(Quad) and take your standard texture coordinates for rendering the texture so its fits completely over the surface and modify them to : TextureCoord * (Size/TextureSize) + Offset/TextureSize .

BTW, when you draw whatever your drawing(Not talking about the grid but whats drawn on top of it), you should render it using Polygons/Triangles rather than lines as they are faster. You can use glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); to switch to wireframe and glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); to switch back.


The following code has not been tested. Note that you shouldn't use glBegin/glEnd but its easier to make example code with them :P .
Code:
  1.  
  2. Procedure DrawGrid(X,Y,Width,Height,OffsetX,OffsetY : Integer);
  3. const
  4.  Data : Array [0..7] of Single = (0,0,0,1,1,1,1,0);
  5.  TextureWidth = 8;
  6.  TextureHeight = 8;
  7. var
  8.  X : Byte;
  9. begin
  10.  glBindTexture(Target, GridTexture);
  11.  glBegin(GL_POLYGON);
  12.   for X := 0 to 3 do
  13.   begin
  14.    glTexCoord2f(Data[0+X*2]*(Width/TextureWidth)+(OffsetX/TextureWidth),Data[1+X*2]*(Height/TextureHeight)+(OffsetY/TextureHeight));
  15.    glVertex2f(X+Data[0+X*2]*Width,Y+Data[1+X*2]*Height);
  16.   end;
  17.  glEnd;
  18. end;

Autor:  NoDPI [ Mi Feb 27, 2013 17:03 ]
Betreff des Beitrags:  Re: Just Beginning

Blorp..

Bild

Spurious things appear :(

<rant>
</rant>

Sigh..

Once again thanks for the help and suggestions.

I shall now fade away.

Autor:  Stucuk [ Do Feb 28, 2013 00:10 ]
Betreff des Beitrags:  Re: Just Beginning

Looks grid like, whats the problem?

Seite 2 von 2 Alle Zeiten sind UTC + 1 Stunde
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/