Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Sa Dez 21, 2024 13:14

Foren-Übersicht » English » English Programming Forum
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 20 Beiträge ]  Gehe zu Seite Vorherige  1, 2
Autor Nachricht
 Betreff des Beitrags: Re: Just Beginning
BeitragVerfasst: Mi Feb 27, 2013 00:36 
Offline
DGL Member
Benutzeravatar

Registriert: Sa Aug 18, 2007 18:47
Beiträge: 694
Wohnort: Köln
Programmiersprache: Java
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

_________________
Es werde Licht.
glEnable(GL_LIGHTING);
Und es ward Licht.


Zitat aus einem Java Buch: "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off"

on error goto next


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Just Beginning
BeitragVerfasst: Mi Feb 27, 2013 12:27 
Offline
DGL Member

Registriert: Fr Feb 22, 2013 13:43
Beiträge: 9
Programmiersprache: Lazarus FPC Linux
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.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Just Beginning
BeitragVerfasst: Mi Feb 27, 2013 15:19 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
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;

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Just Beginning
BeitragVerfasst: Mi Feb 27, 2013 17:03 
Offline
DGL Member

Registriert: Fr Feb 22, 2013 13:43
Beiträge: 9
Programmiersprache: Lazarus FPC Linux
Blorp..

Bild

Spurious things appear :(

<rant>
</rant>

Sigh..

Once again thanks for the help and suggestions.

I shall now fade away.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Just Beginning
BeitragVerfasst: Do Feb 28, 2013 00:10 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
Looks grid like, whats the problem?

_________________
Free Map Editor - Game Requirements - Stucuk.Net
-Stu


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 20 Beiträge ]  Gehe zu Seite Vorherige  1, 2
Foren-Übersicht » English » English Programming Forum


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 1 Gast


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.009s | 15 Queries | GZIP : On ]