Relevant Details(Maybe)OS: Windows 7 64 bit.
Graphics Card: NVidia GT 610
Hey there guys! As you can no doubt probably tell I'm new here. I think I put this in the right place as its related to OpenGL.
I'm relatively out of the loop when it comes to using Lazarus and even more so with OpenGL. So forgive me if I do something really dumb. While
http://wiki.freepascal.org/OpenGL_Tutorial does cover much of the information I seem to need to know it does leave some stuff out for someone of my skill level and familiarity.
There are two problems I am having working with OpenGL currently and would like somebody who knows what they are doing to explain to me what stupid stuff I'm doing wrong.
Note: Please forgive the awful spacing and such as when I set custom settings in Lazarus for tabbing and such it gives really really weird results when I paste it places.Problem A: Textures simply don't work. I added pl_vampyreimaging to the project inspector but then its missing the ImagingOpenGL file so I either added it in manually or added it in through project inspector.(I feel this is a mistake somehow but I have no other idea of how to actually use/install it)
Overall it seemed to work with no errors but no textures appear and instead I get a white square in the middle of the screen. I intended the square to be in the middle of the screen taking up only a little bit of space but at the same time I did not intend for it to be blank.
The code for it is here...
unit PGLSampleCode;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, OpenGLContext, gl, Forms, Controls, Graphics,
Dialogs, ExtCtrls, ImagingOpenGL;
type
{ TForm1 }
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure GLPaint(Sender: TObject);
private
public
GLBox: TOpenGLControl;
end;
var
Form1: TForm1;
MyImage: GLuint;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
GLBox := TOpenGLControl.Create(Form1);
GLBox.AutoResizeViewport := true;
GLBox.Parent := Form1;
GLBox.MultiSampling := 4;
GLBox.Align := alClient;
GLBox.OnPaint := @Form1.GLPaint;
GLBox.invalidate;
MyImage := LoadGLTextureFromFile('test2.bmp');
glEnable(GL_TEXTURE_2D);
end;
procedure TForm1.GLPaint(Sender: TObject);
begin
glClearColor(0,0.2,1, 1);
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
glLoadIdentity;
glBindTexture(GL_TEXTURE_2D, MyImage);
glBegin(GL_QUADS);
glTexCoord2f(1, 0);
glVertex3f( 0.5, 0.5, 0);
glTexCoord2f(0, 0);
glVertex3f(-0.5, 0.5, 0);
glTexCoord2f(0, 1);
glVertex3f(-0.5,-0.5, 0);
glTexCoord2f(1, 1);
glVertex3f( 0.5,-0.5, 0);
glEnd;
GLBox.SwapBuffers;
end;
end.
Problem B: Display lists never work for me.. like ever...
I'm sure its something to do with the way I'm reading it or maybe something else, however, I also read that they are deprecated. Thats quite awkward for me as I know no other way to write it using said freepascal wiki guide. Yet I tried a sample OpenGL program and I'm pretty sure it had them and worked perfectly fine.
It makes me think I'm just doing something wrong. In which case its probably an easy fix.
The code for this one is here...
unit PGLSampleCode;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, OpenGLContext, gl, Forms, Controls, Graphics,
Dialogs, ExtCtrls, ImagingOpenGL;
type
{ TForm1 }
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure GLPaint(Sender: TObject);
private
public
GLBox: TOpenGLControl;
end;
var
Form1: TForm1;
MyImage: GLuint;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
GLBox := TOpenGLControl.Create(Form1);
GLBox.AutoResizeViewport := true;
GLBox.Parent := Form1;
GLBox.MultiSampling := 4;
GLBox.Align := alClient;
GLBox.OnPaint := @Form1.GLPaint;
GLBox.invalidate;
MyImage := LoadGLTextureFromFile('test2.bmp');
glEnable(GL_TEXTURE_2D);
glNewList(1,GL_Compile);
glBegin(GL_QUADS);
glTexCoord2f(1, 0);
glVertex3f( 0.5, 0.5, 0);
glTexCoord2f(0, 0);
glVertex3f(-0.5, 0.5, 0);
glTexCoord2f(0, 1);
glVertex3f(-0.5,-0.5, 0);
glTexCoord2f(1, 1);
glVertex3f( 0.5,-0.5, 0);
glEnd;
glEndList;
end;
procedure TForm1.GLPaint(Sender: TObject);
begin
glClearColor(0,0.2,1, 1);
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
glLoadIdentity;
glBindTexture(GL_TEXTURE_2D, MyImage);
glCallList(1);
GLBox.SwapBuffers;
end;
end.
I'd appreciate any help I could get and appreciate your time even reading this. If you need any further details let me know and I'll get back to you as fast as I can, probably tomorrow, as my timezone is USA Eastern Standard Time.