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

Aktuelle Zeit: Do Mai 16, 2024 09:12

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



Ein neues Thema erstellen Auf das Thema antworten  [ 7 Beiträge ] 
Autor Nachricht
 Betreff des Beitrags: RenderToTexture + Transparency
BeitragVerfasst: Mo Apr 20, 2009 00:20 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
Im wondering if it is possible to have transparency when you render to a texture. I.E You render a cube which is solid, but every other pixel would be transparent.

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


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mo Apr 20, 2009 08:10 
Offline
DGL Member
Benutzeravatar

Registriert: Do Dez 05, 2002 10:35
Beiträge: 4234
Wohnort: Dortmund
Depends on what kind of render to texture you are using? If you are using FrameBufferObjects i think its no problem. With pBuffers or normal copy from framebuffer you have to create an context with alphachannel. And you should verify this. The drivers have the right to ignore your wish. But i prefer the use of FrameBufferObjects. If its possible. Else you have to set the Alpha Paramater of the PixelFormatDescription while your contextcreation (CreateRenderingContext in the dglOpenGL.pas). After you have choosen your pixelformat you have to call DescribePixelformat and read all values of the fomat. If there is an alphavalue you have an alphachannel. If there isn't an alphavalue the driver ignores you.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Di Apr 21, 2009 00:14 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
I assume FrameBufferObjects are cheaper to use than copying from the framebuffer?

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


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Di Apr 21, 2009 07:55 
Offline
DGL Member
Benutzeravatar

Registriert: Do Dez 05, 2002 10:35
Beiträge: 4234
Wohnort: Dortmund
Thats right. Because you have to attach real textures to the FBO. So OpenGL renders directly into textures and the workflow is much better for the asynchronous GPU.

But FBOs has higher requirement for OpenGL. The first version of OpenGL they support FBOs in core is 3.0. Before you have to use the Extension GL_EXT_framebuffer_object. This is so around OpenGL 2.0. I think on moderate hardware this shouldn't be an problem.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Di Apr 21, 2009 20:35 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
It would proberly be best if i implemented all 3 methods. My fathers ATI MOBILITY RADEON 7000 IGP (Which is the worst GFX card in my house) doesn't support FBO's but should support PBuffers. Intel cards iirc can't do pbuffers right even tho they have the extention. UFO Afterlight which iv helped maintain wouldn't work with intel cards due to the lack of WGL_ARB_pixel_format which iirc ment that a PBuffer couldn't be setup... Meh been months since i tryed to modify the code to allow Intel GFX cards to work(I don't have an Intel Card to test with).

Well and having a 4th method that would come into effect if alpha channel failed to be setup.



Note: Even if i wanted to use OpenGL 3 (Which i don't plan on doing until say 10 years down the line when all GFX Cards have OpenGL 3) my GFX Card is a Geforce 5900XT (You can all laugh now).

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


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mi Apr 22, 2009 09:26 
Offline
DGL Member
Benutzeravatar

Registriert: Do Dez 05, 2002 10:35
Beiträge: 4234
Wohnort: Dortmund
I think it's not necessary to implement all three ways. It should be enough if you implement the classic copying from renderbuffer and the new version with FBOs. pBuffers are only a few better than copying from renderbuffer. But you have an seperate context and you need to activate him every time you wants to update the texture. So you have much more work and nearly no (or few) performance changes. And for copy from renderbuffer make sure you have activated the alphachannel and the driver listens to you.

PS: I also dont plan to support OpenGL 3.0 in the next few years. It's not necessary for the projects i do. 3.0 is really overpowered for this.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Mai 17, 2009 17:31 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jul 21, 2004 22:39
Beiträge: 360
Wohnort: UK, Scotland
Iv implemented FBO (Yep took a while for me to get round to it). Im just posting to note some things which GameDev.Net's FBO Tutorial which i used missed out(Incase anyone falls into the same problems).

1. When it comes to begining the FBO render you need to set the glclearcolor to have 0 for the Alpha or you don't get any transparency. (Granted the tutorial wasn't about transparent ones, tho it does use GL_RGBA for the texture)
2. You also have to call glClear after the glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, &fbo) call or the FBO's Texture will always remain black.

Below is some code snipits from the texture class i made(It won't compile without modifications, like a header bit for the TTexture :P):

Code:
  1. function FBOStatusToStr(Status : Cardinal) : String;
  2. begin
  3.  case Status of
  4.   GL_FRAMEBUFFER_COMPLETE_EXT                        : Result := 'GL_FRAMEBUFFER_COMPLETE_EXT';
  5.   GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT           : Result := 'GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT';
  6.   GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT   : Result := 'GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT';
  7.   GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT : Result := 'GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT';
  8.   GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT           : Result := 'GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT';
  9.   GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT              : Result := 'GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT';
  10.   GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT          : Result := 'GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT';
  11.   GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT          : Result := 'GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT';
  12.   GL_FRAMEBUFFER_UNSUPPORTED_EXT                     : Result := 'GL_FRAMEBUFFER_UNSUPPORTED_EXT';
  13.   GL_FRAMEBUFFER_STATUS_ERROR_EXT                    : Result := 'GL_FRAMEBUFFER_STATUS_ERROR_EXT';
  14.   GL_FRAMEBUFFER_BINDING_EXT                         : Result := 'GL_FRAMEBUFFER_BINDING_EXT';
  15.   GL_RENDERBUFFER_BINDING_EXT                        : Result := 'GL_RENDERBUFFER_BINDING_EXT';
  16.   GL_MAX_COLOR_ATTACHMENTS_EXT                       : Result := 'GL_MAX_COLOR_ATTACHMENTS_EXT';
  17.   GL_MAX_RENDERBUFFER_SIZE_EXT                       : Result := 'GL_MAX_RENDERBUFFER_SIZE_EXT';
  18.   GL_INVALID_FRAMEBUFFER_OPERATION_EXT               : Result := 'GL_INVALID_FRAMEBUFFER_OPERATION_EXT';
  19.   else
  20.   Result := 'Unknown Status';
  21.  end;
  22. end;
  23.  
  24. procedure TTexture.CreateFBO;
  25. var
  26.  Status : Cardinal;
  27. begin
  28.  if FTexture = 0 then Exit;
  29.  if FWidth   = 0 then Exit;
  30.  if FHeight  = 0 then Exit;
  31.  if FFBO <> 0 then Exit;
  32.  if FDepthBuffer <> 0 then Exit;
  33.  
  34.  glGenFramebuffersEXT(1, @FFBO);
  35.  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FFBO);
  36.  
  37.  glGenRenderbuffersEXT(1, @FDepthBuffer);
  38.  glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, FDepthBuffer);
  39.  glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, FWidth, FHeight);
  40.  glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, FDepthBuffer);
  41.  
  42.  glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, FTexture, 0);
  43.  
  44.  Status := glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
  45.  if Status <> GL_FRAMEBUFFER_COMPLETE_EXT then
  46.  Feedback('TTexture.CreateFBO','Frame Buffer not Setup Correctly. Status: ' + FBOStatusToStr(Status),FEEDBACK_ERROR);
  47.  
  48.  glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
  49.  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
  50. end;
  51.  
  52. procedure TTexture.BeginFBO;
  53. begin
  54.  OGLWrapper.GetBackgroundColor(FClearColor[0],FClearColor[1],FClearColor[2]);
  55.  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FFBO);
  56.  glPushAttrib(GL_VIEWPORT_BIT);
  57.  
  58.  glClearColor(1,1,1,0);
  59.  glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);   // Clear The Screen And The Depth Buffer
  60.  
  61.  glViewport(0,0,FWidth, FHeight);
  62.  glLoadIdentity();
  63. end;
  64.  
  65. procedure TTexture.EndFBO;
  66. begin
  67.  glPopAttrib();
  68.  glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
  69.  
  70.  glClearColor(FClearColor[0]/255,FClearColor[1]/255,FClearColor[2]/255,1);
  71.  glClear(GL_COLOR_BUFFER_BIT); //Update the Background Color
  72. end;
  73.  
  74. procedure TTexture.ResizeFBO;
  75. begin
  76.  if FFBO = 0 then Exit;
  77.  if FDepthBuffer = 0 then Exit;
  78.  glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, FDepthBuffer);
  79.  glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, FWidth, FHeight);
  80.  glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
  81. end;
  82.  
  83. procedure TTexture.CreateNullTexture(Width,Height : Integer; Target : Cardinal = $0DE1);
  84. begin
  85.  if FTexture = 0 then
  86.  glGenTextures(1, @FTexture);
  87.  BindTexture(Target);
  88.  
  89.  
  90.  glTexImage2D(Target, 0, GL_RGBA8,  width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, Nil);
  91.  
  92.  //Assign the mip map levels
  93.  glTexParameteri(Target,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  94.  glTexParameteri(Target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
  95.  
  96.  glGenerateMipmapEXT(Target);
  97.  glBindTexture(Target,0);
  98.  
  99.  if (FFBO <> 0) and ((FWidth <> Width)or (FHeight <> Height)) then
  100.  ResizeFBO;
  101.  
  102.  FWidth          := Width;
  103.  FHeight         := Height;
  104. end;

_________________
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  [ 7 Beiträge ] 
Foren-Übersicht » English » English Programming Forum


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 2 Gäste


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.032s | 17 Queries | GZIP : On ]