DGL
https://delphigl.com/forum/

Simple OpenGL/DirectX application to display images-HELP ME
https://delphigl.com/forum/viewtopic.php?f=19&t=5349
Seite 1 von 5

Autor:  Aro [ So Mär 19, 2006 13:04 ]
Betreff des Beitrags:  Simple OpenGL/DirectX application to display images-HELP ME

Hello

I have checked tutorials here and Jan Horn demos but
the thing is too complicated for me;(

Could someone be so kind to write an app for me which
will preload for example 10 or more jpgs to memory
and be abble to display them one-by-one without page flickering?
I wish the jpgs would be like 1280x1024 or even 1600x1200.

I think OpenGL or DirectX etc would be the direction
for this application.

I wish to create a simple animation from these jpgs.

*C++ Builder 6* or Delphi would be the best for me.

I would kindly ask you to contact me by icq: 47223521
or by email: sp@sw.pl

Thank you!
Arek



Hallo Ich habe Tutorials hier und Jan Horn demos überprüft, aber die Sache ist für me zu schwierig:(
Könnte jemand so freundlich sein, eine APP für mich zu schreiben, welches 10 zum Beispiel oder mehr jpgs
zum Gedächtnis vorbelastet und abble ist, sie one-by-one anzuzeigen, ohne Seite zu flackern?

Ich denke, daß OpenGL oder DirectX usw. die Richtung für diese Anwendung sein würden.

Ich möchte eine einfache Animation von diesen jpgs verursachen.

* C++ Builder 6 * oder Delphi würde für mich das beste sein.

Ich würde Sie freundlich bitten, mit mir durch icq in Verbindung zu treten: 47223521
oder durch email: sp@sw.pl

Danke!
Arek

Ps: I can speak English only:(

Autor:  Flash [ So Mär 19, 2006 14:50 ]
Betreff des Beitrags: 

Most of use are not fans of "alien coding", but we would help you to get the problem solved.

Yes you are right: OpenGL can do what you whant.

If you whant to use Delphi as language I can recommend glBitmap.pas from LossyX (our texture specialist).
But I'm not shure about the handling of that texture sizes. Because older grafic cards are used to "power of 2"-textures (means the size was for instance 512x512 or 1024x256 or something). But ... hmm ... I think even this is handled by glBitmap.pas.

The only thing you have to do is taking one of your templates an build a texture-manager on basis of the glBitmap.pas.

so far...

Autor:  Lossy eX [ Mo Mär 20, 2006 14:16 ]
Betreff des Beitrags: 

I also think like Flash. We are not here to code your apps but we can help you to do it self.

For simple animations its possible to use texture_rectangle. In this case you dosn't have to perform any changes on the textures. Its really easy to implement it with the glbitmap loader. And the best its supported by older graphiccard.

If you are intrested to learn more we can help you.

Autor:  Flash [ Mo Mär 20, 2006 14:39 ]
Betreff des Beitrags: 

This is the answer to your PM you send to me:

First check out our OpenGL-Templates (1.5 for VCL): http://www.delphigl.com/download.php?cat=1

You can modify it easily that it doesn't use the whole form but a panel for rendering. After you made this work, you will see your very first OpenGL output.

After this we will help you with this steps:

1. Changing perspective to ortho mode (glOrtho)
2. Displaying a white quad all over your rendering context (glBegin(GL_QUADS))
3. Loading Textures by using glBitmap.pas
4. Displaying Textures in your scene

After that small steps you will have your first picture rendered. Thats realy no big thing. It is more difficult do build a usable interface. But this is a problem you should be able to solve.

Autor:  AL [ Mo Mär 20, 2006 19:10 ]
Betreff des Beitrags: 

Zitat:
Ps: I can speak English only:(


Well I doubt that Google has better skills concerning our language :wink: and as most(/all) of us are capable of reading and writing in english, it isn't necessary to translate your posts. In fact the german translation is a bit confusing ^^.

Autor:  Aro [ Mo Mär 20, 2006 21:01 ]
Betreff des Beitrags: 

I was playing with a few tutorials. I had problem to bind OpenGL
display to Form1->Panel1.

I can't use API Windows ( it is a black magic to me)
I wish to use VCL Form Panel to display OpenGL

I will download the files you suggested and try to follow your advices.

I am really grateful for your time people. Thank you.

Autor:  Aro [ Mo Mär 20, 2006 21:48 ]
Betreff des Beitrags: 

ok. i have OpenGL in Panel Window.
Where can i find glBitmap.pas?

I have found in some example "glBMP.pas" size:63380 bytes, from 2002 year.
Is this the file i need or not?

What to do now?
Could you help me with the remaining points?

Autor:  i0n0s [ Mo Mär 20, 2006 22:00 ]
Betreff des Beitrags: 

glBitmap.pas ;)
and because of the hidden link for non german people:
http://www.dev-center.de/index.php?cat=header&file=glbitmap

Autor:  Aro [ Mo Mär 20, 2006 22:24 ]
Betreff des Beitrags: 

ok. i have glbitmap. thanks.

i did a few things.

point 3 ( ?? ) :

private
{ Private-Deklarationen }
fTexture: TglBitmap2D; // i have added this to the object declaration

procedure TGLForm.FormShow(Sender: TObject);
begin
fTexture := TglBitmap2D.Create; // Instanz der Klasse erstellen
fTexture.LoadFromFile('d:\testimage.jpg'); // Datei laden
fTexture.GenTexture(False);
fTexture.Bind;
end;


points: 1,2, 3(?), 4 :)

i'm waiting for help to move on:)

Autor:  Flash [ Mo Mär 20, 2006 22:44 ]
Betreff des Beitrags: 

Ok...

Did the code you have, render something in your panel? A triangle ore something?

If no, look at this:

Code:
  1.  
  2. glBegin(GL_QUADS);
  3.   glVertex3f(-1, 1, 0);
  4.   glVertex3f(-1,-1, 0);
  5.   glVertex3f( 1,-1, 0);
  6.   glVertex3f( 1, 1, 0);
  7. glEnd;


Put this inside of your "render" function. This will draw a rectangle on your screen. The rectangle is the basis for your pictures. The will be mapped on this rectangle as textures. So the rectangel is a kind of canvas.


After you have got the quad on your panel, we can move to Step 2: glOrtho.

Search in your code for gluPerspective and replace it with glOrtho(0,Panel.width,0,panel.height, 0,128);

When you start your app you will see nearly nothing. Because the resolution is now pixel precise. So the quad is only 2x2 pixel. You have to change the Vertex-Coords to (0,0)-(panel.width, panel.height). After that you will have the quad all over your panel.

(How should I do this Vertex-Coord-Transfor thing? Just look at the code above. You will find it out. But remark: The order of the coords is important and must be counter clockwise.)

Autor:  Aro [ Mo Mär 20, 2006 23:31 ]
Betreff des Beitrags: 

I need to quote my code.

1.
After i have loaded 800x600 texture the application almost freezes. framerate drops to 0.5 fps.
I must have put this in the wrong place...

2. OpenGL viewport became all white [ when Form.Create texture load is commented out ]
even if i add "-50" to the vertex coordinates

3. Where should i assign texture to that quad?

Code:
  1.  ..
  2.   private
  3.     { Private-Deklarationen }
  4.     fTexture: TglBitmap2D; //ja
  5.  ...
  6.  
  7. procedure TGLForm.FormCreate(Sender: TObject);
  8. begin
  9. InitOpenGL;
  10. DC := GetDC(panel.Handle);
  11. RC := CreateRenderingContext(DC, [opDoubleBuffered], 32, 24, 0, 0, 0, 0);
  12. ActivateRenderingContext(DC, RC);
  13. glEnable(GL_DEPTH_TEST);
  14. glDepthFunc(GL_LESS);
  15. glClearColor(0,0,0,0);
  16. BuildFont('MS Sans Serif');
  17. Application.OnIdle := Render;
  18. StartTick := GetTickCount;
  19.  
  20. // now i have added texture load function
  21. fTexture := TglBitmap2D.Create; // Instanz der Klasse erstellen
  22. fTexture.LoadFromFile('d:\test-texture-800x600.jpg'); // Datei laden
  23. fTexture.GenTexture(False);  // i have put her "false" to skip texture 512x512 size check.
  24. fTexture.Bind;
  25. end;
  26.  
  27.  
  28. procedure TGLForm.Render(Sender: TObject; var Done: Boolean);
  29. begin
  30. glMatrixMode(GL_PROJECTION);
  31. glLoadIdentity;
  32. glViewPort(0, 0, ClientWidth, ClientHeight);
  33. //gluPerspective(60, ClientWidth/ClientHeight, 1, 128);
  34. glOrtho(0,panel.width,0,panel.height, 0,128);
  35. glMatrixMode(GL_MODELVIEW);
  36. glLoadIdentity;
  37. glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  38. ShowText;
  39.  
  40. glBegin(GL_QUADS);
  41. glVertex3f(0, 0, 0);
  42. glVertex3f(0,panel.Height, 0);
  43. glVertex3f( panel.Width,panel.Height, 0);
  44. glVertex3f( panel.Width, 0, 0);
  45. glEnd;
  46.  
  47. SwapBuffers(DC);
  48. Done := False;
  49. inc(Frames);
  50. // FPS aktualisieren
  51. if GetTickCount - StartTick >= 500 then
  52.  begin
  53.  FPS       := Frames/(GetTickCount-StartTick)*1000;
  54.  Frames    := 0;
  55.  StartTick := GetTickCount
  56.  end;
  57.  
  58. end;



What is wrong with this code?

Autor:  Flash [ Mo Mär 20, 2006 23:54 ]
Betreff des Beitrags: 

First: Please use our pascal-tags. So much unformatted code nearly blinds us ;)

Ok... let me look....

@1: This is possible.

@2: This is normal if you are in Ortho-Mode. The z-direction is used for stacking the different layers. It has nearly no effekt on the position. Its all White because your quad is now "fullscreen" on your panel. You see just the quad, nothing else.

@3: After you have loaded an bound the texture you must give so called texture coordinates. The comand for this is glTexCoord2f(). With glTexCoord(0,0) you map the upper left corner to the folowing vertex. With glTexCoord2f(0,1) you map the lower right corner to the following vertex, and so on. That means, you have to write glTexCoord3f(); glVertex3f(); inside your glBegin/glEnd block.

You also have to enable Texturing (glEnable(GL_TEXTURE_2D)). This should be done once at the beginning. And for your application you can let it enabled all over the time.

Autor:  Aro [ Di Mär 21, 2006 00:14 ]
Betreff des Beitrags: 

ok i have managed to display this 800x600 size texture in Form1 Panel.
but..
"SPEED"

this application freezes when resized and 0.05 fps when ide.


Could you tell me what to do?

This application naturally uses onIdle to execute "Render" function in loop.

I have put :

Code:
  1. fTexture := TglBitmap2D.Create;
  2. fTexture.LoadFromFile('d:\testimage.jpg');
  3. fTexture.GenTexture(False);
  4. fTexture.Bind;


in the FormCreate function to avoid loading texture in loop from disk.

How to speed up this application?
It can't be so slow;)


// edit Lossy: Pascaltags added

Autor:  Lossy eX [ Di Mär 21, 2006 09:00 ]
Betreff des Beitrags: 

Code:
  1. fTexture.GenTexture(False); // i have put her "false" to skip texture 512x512 size check.

The optional Parameter has an reason. But only for advanced Developers they 100 percently know what they do. When you call GenTextures with True you get an exception. Is it Right? I think. When the glbitmap raised an error it has an reason.

In my earlier post i speak about an TextureRectangle extension. To use this extension you must told the glbitmap to use an other target for the texture. It looks like so.
Code:
  1. fTexture.Target := GL_TEXTURE_RECTANGLE_ARB;
  2. fTexture.GenTexture(True);


Please open the glBitmap an go to Line 2226 and remove the (* and *) from the line.
Code:
  1.  
  2. // Line before
  3.       TexRec := (GL_ARB_texture_rectangle (*or GL_EXT_texture_rectangle*) or GL_NV_texture_rectangle) and
  4.  
  5. // Line after
  6.       TexRec := (GL_ARB_texture_rectangle or GL_EXT_texture_rectangle or GL_NV_texture_rectangle) and

An the Same in line 3077.

I must comment these extension because our header dosnt supported it at this time. But i have implemented it in our 2.0 header. On ATI graphiccards only the EXT version of the TextureRectangle extension is supported.

The next thing you must do ist to set your Texturecoordinates. For Texture without TextureRectangle the coordinates are between 0 and 1. With TextureRectangle they were between 0 and the Height or the Width of the image. In you code it must look like.
Code:
  1. fTexture.Bind;
  2.  
  3. glBegin(GL_QUADS);
  4.   glTexCoord2i(0, 0);
  5.   glVertex3f(0, 0, 0);
  6.  
  7.   glTexCoord2i(0, fTexture.Heigth);
  8.   glVertex3f(0, panel.Height, 0);
  9.  
  10.   glTexCoord2i(fTexture.Width, fTexture.Height);
  11.   glVertex3f(panel.Width, panel.Height, 0);
  12.  
  13.   glTexCoord2i(fTexture.Width, 0);
  14.   glVertex3f(panel.Width, 0, 0);
  15. glEnd;

i dont know if they were drawn correctly.

Autor:  Aro [ Di Mär 21, 2006 12:27 ]
Betreff des Beitrags: 

GREAT!
Using your help i was able to do what i intended to do.
I had to change viewport too because it was set do ClientWidth and ClientHeight.

I have managed to prepare 2 textures during FormCreate event and
be able to switch them using timer.

I have noticed that when i set timer to 30ms ( 30 fps? ) and the two
textures are swiched i see flicker effect.

Do you know how to get rid of flicker? Maybe some offscreen biding
and some switching?

my ontimer procedure looks like this:

Code:
  1. if picno=1 then
  2. begin
  3.   fTexture:=fTexture2;
  4.   fTexture.Bind;
  5.   picno:=2;
  6. end
  7. else
  8. if picno=2 then
  9. begin
  10.   fTexture:=fTexture1;
  11.   fTexture.Bind;
  12.   picno:=1;
  13. end;


it switches textures but that ugly flicker effect...


// edit Lossy: Pascaltags added and code formated

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