Lazarus
Programming => Graphics and Multimedia => OpenGL => Topic started by: carlejt on June 23, 2011, 06:56:34 am
-
Hello
My problem is to represent the view of two polygons in 3D, using Free Pascal and OpenGL at fullscreen mode 640x480;
Note: In each polygon draw the image of a bitmap.
1) Position of eye: (20, 20, 20)
2) Point of observation: (0, 0, 0)
3) Vector Up the camera: (-1, -1, 1)
4) Visual Angle: 45
5) Distance Far: 50
6) Near Distance: 0.1
7) The vertices of the polygon 1 are: (0, 0, 0), (1, 1, 0), (2, 0, 0) with a bitmap 1 of 640x480. (occupying the area of the polygon)
8> The vertices of the polygon 2 are: (0, 0, 5), (1, 1, 5), (2, 0, 5) with a bitmap 2 of 320x200. (occupying the area of the polygon)
The code (free pascal) for this program-problem would be helpful. (please).
Any suggestions would help.
Thanks.
-
Have you tried GLScene?
-
Hello
Thanks for responding. I've tried but I failed to install. I followed the instructions in http://wiki.lazarus.freepascal.org/GLScene.
Actually I want to know what would be the code of the program the problem I raised. It would be helpful.
-
I think those instructions are a bit outdated.
Just download GLScene from www.glscene.org.
I downloaded the Snapshot for SVN revision 5593 last week and it installed fine in lazarus 0.9.30.
From lazarus do Package -> open package file
and then select glscene_runtime.lpk in the /Lazarus directory of GLScene (or the other one, don't remember). Lazarus will add the other required packages automatically.
-
Try the OpenGL example, then try solving the problem yourself. When stuck, post your code so far and explain what you have done and what's missing.
-
I have followed the example TEXTURES Tutorial OpenGL but I can not compile it. I have the library glut32.dll.
This is the example TEXTURES del tutorial OpenGL:
program textures;
{$mode objfpc}{$H+}
uses
gl, glu, glut, ImagingOpenGL;
const
AppWidth = 640;
AppHeight = 480;
LIST_OBJECT = 1;
var
Tex1, Tex2: GLuint;
procedure InitializeGL;
begin
glClearColor(0, 0, 0, 0);
Tex1 := LoadGLTextureFromFile('ashwood.bmp');
Tex2 := LoadGLTextureFromFile('Flare.bmp');
glEnable(GL_TEXTURE_2D);
end;
procedure CreateList;
begin
glNewList(LIST_OBJECT, GL_COMPILE);
glBegin(GL_QUADS);
glTexCoord2f(1, 0);
glVertex3f( 2, 2, 0);
glTexCoord2f(0, 0);
glVertex3f(-2, 2, 0);
glTexCoord2f(0, 1);
glVertex3f(-2,-2, 0);
glTexCoord2f(1, 1);
glVertex3f( 2,-2, 0);
glEnd;
glEndList;
end;
procedure DrawGLScene; cdecl;
begin
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
glLoadIdentity;
glTranslatef(-5, 0, -15);
glBindTexture(GL_TEXTURE_2D, Tex1);
glCallList(LIST_OBJECT);
glLoadIdentity;
glTranslatef(0, 0, -15);
glBindTexture(GL_TEXTURE_2D, Tex2);
glCallList(LIST_OBJECT);
glLoadIdentity;
glTranslatef(5, 0, -15);
glBindTexture(GL_TEXTURE_2D, Tex1);
glCallList(LIST_OBJECT);
glEnable(GL_BLEND);
glBlendFunc(GL_ZERO, GL_SRC_COLOR);
glLoadIdentity;
glTranslatef(5, 0, -15);
glBindTexture(GL_TEXTURE_2D, Tex2);
glCallList(LIST_OBJECT);
glDisable(GL_BLEND);
glutSwapBuffers;
end;
procedure ReSizeGLScene(Width, Height: Integer); cdecl;
begin
if Height = 0 then
Height := 1;
glViewport(0, 0, Width, Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity;
gluPerspective(45, Width / Height, 0.1, 1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
end;
procedure GLKeyboard(Key: Byte; X, Y: Longint); cdecl;
begin
if Key = 27 then
begin
glDeleteLists(LIST_OBJECT, 1);
Halt(0);
end;
end;
procedure glutInitPascal(ParseCmdLine: Boolean);
var
Cmd: array of PChar;
CmdCount, I: Integer;
begin
if ParseCmdLine then
CmdCount := ParamCount + 1
else
CmdCount := 1;
SetLength(Cmd, CmdCount);
for I := 0 to CmdCount - 1 do
Cmd[I] := PChar(ParamStr(I));
glutInit(@CmdCount, @Cmd);
end;
var
ScreenWidth, ScreenHeight: Integer;
begin
glutInitPascal(True);
glutInitDisplayMode(GLUT_DOUBLE or GLUT_RGB or GLUT_DEPTH);
glutInitWindowSize(AppWidth, AppHeight);
ScreenWidth := glutGet(GLUT_SCREEN_WIDTH);
ScreenHeight := glutGet(GLUT_SCREEN_HEIGHT);
glutInitWindowPosition((ScreenWidth - AppWidth) div 2, (ScreenHeight - AppHeight) div 2);
glutCreateWindow('OpenGL Tutorial :: Textures');
InitializeGL;
CreateList;
glutDisplayFunc(@DrawGLScene);
glutReshapeFunc(@ReSizeGLScene);
glutKeyboardFunc(@GLKeyboard);
glutMainLoop;
end.
Anyone know where to find these examples with the Vampyre Imaging Library units for Free Pascal.
On page
http://imaginglib.sourceforge.net/index.php?page=down
Downloaded the Imaging0.26.4. What are the units for free pascal for compile the code TEXTURES?
Not only is the unit ImagingOpenGL.
-
I'm assuming that this is some sort of school project and that learning modern opengl is not really on the agenda. so here is a site that should help you learn the older more user friendly opengl that most of us grew to love.
http://www.freepascal-meets-sdl.net/
also you should check out this site as many people there use sdl and opengl
http://www.pascalgamedevelopment.com/