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

Aktuelle Zeit: Fr Jul 18, 2025 11:14

Foren-Übersicht » Programmierung » OpenGL
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 14 Beiträge ] 
Autor Nachricht
 Betreff des Beitrags: mirror texture how?
BeitragVerfasst: Di Jan 06, 2004 19:28 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
ich mochte ein mirror texture rendern von meiner scene. Das gelingt mir aber nicht. Das result solte sein wie http://www.delphi3d.net/listfiles.php?category=8 wie beim texreflect example.
Ist fur diesen thema auch ein (simple) example/tutorial?
Alles wirkt in das example nur das texture wird nicht (filled).


Du hast keine ausreichende Berechtigung, um die Dateianhänge dieses Beitrags anzusehen.

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Di Jan 06, 2004 19:40 
Offline
DGL Member
Benutzeravatar

Registriert: Mo Sep 23, 2002 19:27
Beiträge: 5812
Programmiersprache: C++
Could you describe how you render to texture (I personally don't like going to someone else's sources)? Are you just using plain render to texture via glCopy(Sub)TexImage2D or do you use a pixel buffer? Just post the important part of your source and I'll try to help.

_________________
www.SaschaWillems.de | GitHub | Twitter | GPU Datenbanken (Vulkan, GL, GLES)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Di Jan 06, 2004 20:00 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
It is glCopyTexSubImage2D. Below is the part that should update the texture:

procedure UpdateMirror;
const
CP: array [0..3] of Double = (0, 1, 0, 0);
begin

// Update the reflection texture.
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);

glViewport(0, 0, M_SIZE, M_SIZE);

glMatrixMode(GL_TEXTURE);
glLoadIdentity;
glMatrixMode(GL_MODELVIEW);
// Mirror the scene relative to the YZ plane:
glLoadMatrixf(@cM);
glScalef(1, -1, 1);

glLightfv(GL_LIGHT0, GL_POSITION, @POS);

// Render everything above sea level:
glEnable(GL_CLIP_PLANE0);
glClipPlane(GL_CLIP_PLANE0, @CP);
DrawObjects;
glDisable(GL_CLIP_PLANE0);

// Copy to the texture:
glBindTexture(GL_TEXTURE_2D, mirror);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, M_SIZE, M_SIZE);

glViewport(0, 0, 800, 600);

// Configure the texture matrix to apply the reflection texture.
glMatrixMode(GL_TEXTURE);
glLoadIdentity;
glTranslatef(0.5, 0.5, 0);
glScalef(0.5, 0.5, 0);
// Important: aspect ratio must be that of the main window, not that of the texture.
gluPerspective(60, 800/600, 0.01, 100000);
glMultMatrixf(@cM);
glScalef(1, -1, 1);
glMatrixMode(GL_MODELVIEW);

end;

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Di Jan 06, 2004 20:14 
Offline
DGL Member
Benutzeravatar

Registriert: Mo Sep 23, 2002 19:27
Beiträge: 5812
Programmiersprache: C++
That code looks OK to me. Are you sure that you have created the texture to render your mirror to corretcly? Are it's dimensions power of two and do you also initialize the mirrortexture with a single call to glCopyTexImage2D and the right parameters?

_________________
www.SaschaWillems.de | GitHub | Twitter | GPU Datenbanken (Vulkan, GL, GLES)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Di Jan 06, 2004 20:31 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
i just found out that the problem comes from rendering the 3ds mesh. Hmm...

Thanks sos.

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mi Jan 07, 2004 19:25 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
things are working for one mirror surface now, but how can i get two? and at other places then 0,0,0?

I think i should use the position of the mirrored surface in 3d space and invert that (and not the camera position).
Use clipping at the position of the mirrored surface in 3d space.

But for now it seems than on getting the second surface not the second texture is modified but the first one is. I am still using glCopyTexSubImage2D. Are there some official docs on this command?

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mi Jan 07, 2004 19:54 
Offline
DGL Member
Benutzeravatar

Registriert: Mo Sep 23, 2002 19:27
Beiträge: 5812
Programmiersprache: C++
Free mirrors (at every position you want) isn't that easy. But there was an article on virtual camera positions recently on gamedev.net, that explains how to use VCPs for free mirrors.
And as for the glCopxTexImage2D : You'll have to use a seperate texture for every mirror in your scene. One texture for two or more mirrors won't work.

_________________
www.SaschaWillems.de | GitHub | Twitter | GPU Datenbanken (Vulkan, GL, GLES)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mi Jan 07, 2004 19:59 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
i do use two textures, but still only the first one gets updated with the details of the second.

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mi Jan 07, 2004 20:10 
Offline
DGL Member
Benutzeravatar

Registriert: Mo Sep 23, 2002 19:27
Beiträge: 5812
Programmiersprache: C++
How do you generate those textures? Normally you do something like this :
# Render Scene from mirror one's POV
# Copy framebuffer's content to texture 1
# Render Scene from mirror two's POV
# Copy framebuffer's content to texture 2

Is that how you do it? Could you post some source?

_________________
www.SaschaWillems.de | GitHub | Twitter | GPU Datenbanken (Vulkan, GL, GLES)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Do Jan 08, 2004 19:48 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
it is the texturematrix that goes wrong or right for that matter. I now read it out and restore it. Then i apply it when needed.

i now goin to read the vcp article to see if get how it works. It is a pitty the example is using directx.

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Sa Jan 10, 2004 15:29 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
i do not quite understand the rotating part in vcp.

if i have a mirror that is rotated 35 degrees on the x axis. How do i rotate the scene so it is aligned with the mirror (clipping) pane?

i now can translate a mirror in world space. So i gues i can make one for a standing mirror and one for a shiny floor.

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Jan 11, 2004 14:12 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
This is the mirror texture creation routine now. It allows for moving mirror. How can i add rotation to the mirror texture?

I know i can do a glrotatef to rotate in opengl. But how do i get it alligned to the xy plane?

Code:
  1.  
  2. //create the reflection texture
  3. procedure CreateTexture;
  4. var
  5.   CP: array [0..3] of Double;
  6. begin
  7.   //set up clipping plane
  8.   cp[0]:=0.0; //x
  9.   cp[1]:=0.0; //y
  10.   cp[2]:=1.0; //z
  11.   cp[3]:=0.0; //w
  12.  
  13.   //set up the viewport
  14.   glViewport(0, 0, M_SIZE, M_SIZE);
  15.  
  16.   //clear the buffers
  17.   glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  18.  
  19.   //set the camera pos
  20.   glLoadIdentity;
  21.   glLoadmatrixd(@matM);
  22.  
  23.   //mirror it
  24.   glScalef(1.0, 1.0, -1.0);
  25.  
  26.   //translate the mirror from its position back to 0
  27.   gltranslatef(-waterpos.x,-waterpos.y,-waterpos.z);
  28.  
  29.   //enable clipping plane
  30.   glClipPlane(GL_CLIP_PLANE0, @CP);
  31.   glEnable(GL_CLIP_PLANE0);
  32.  
  33.   //draw the scene...
  34.   DrawObjects;
  35.  
  36.   //disable the clipping plane
  37.   glDisable(GL_CLIP_PLANE0);
  38.  
  39.   //copy the color buffer to a texture creating a new texture if necessary
  40.   if (Reflection <> 0) then
  41.   begin
  42.     glBindTexture(GL_TEXTURE_2D, Reflection);
  43.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
  44.       GL_LINEAR);
  45.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
  46.       GL_LINEAR);
  47.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
  48.       GL_CLAMP);
  49.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
  50.       GL_CLAMP);
  51.     glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0,
  52.       M_SIZE, M_SIZE);
  53.   end else
  54.   begin
  55.     glGenTextures(1, @Reflection);
  56.     glBindTexture(GL_TEXTURE_2D, Reflection);
  57.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
  58.       GL_LINEAR);
  59.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
  60.       GL_LINEAR);
  61.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
  62.       GL_CLAMP);
  63.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
  64.       GL_CLAMP);
  65.     glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0,
  66.       M_SIZE, M_SIZE, 0);
  67.   end;
  68.  
  69.   //restore the viewport
  70.   glViewport(0, 0, WND_XSIZE, WND_YSIZE);
  71. end;
  72.  
[/code]

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Jan 11, 2004 14:39 
Offline
DGL Member
Benutzeravatar

Registriert: Mo Sep 23, 2002 19:27
Beiträge: 5812
Programmiersprache: C++
Please forgive me if this a total shot into the void, but since I'm no math guru. Couldn't you calculate the angle between your xy-plane and the mirror :
Bild
You know p1 and p2, so that you can derive p3 from those two. Now you only need to apply the sine sentence (don't know if it's spelled like this in english. In german it's the "sinus-satz") to get angle alpha, and then just rotate your scene with that angle.

_________________
www.SaschaWillems.de | GitHub | Twitter | GPU Datenbanken (Vulkan, GL, GLES)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Jan 11, 2004 16:46 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
ouch i feel stupid, i was calculation lots of things where i should not have calculated anything at all.

[edit]but this only works when not rotating to much... no 90 degrees[/edit]

If i rotate the mirror forwarard by 30 degrees then when rendering the mirrored scene it has to rotate the scene by -30 degrees.

A complete example is below:

drawobjects; is responsible for drawing the scene

Code:
  1.  
  2. //create the reflection texture
  3. procedure CreateTexture;
  4. var
  5.   CP: array [0..3] of Double;
  6. begin
  7.   //set up clipping plane
  8.   cp[0]:=0.0; //x
  9.   cp[1]:=0.0; //y
  10.   cp[2]:=0.000000001; //z has to be somewhat larger then 0
  11.   cp[3]:=0.0; //w
  12.  
  13.   //set up the viewport
  14.   glViewport(0, 0, M_SIZE, M_SIZE);
  15.  
  16.   //clear the buffers
  17.   glClearColor(0.0, 0.0, 0.1, 0.0);        //  Background color
  18.   glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  19.  
  20.   //set the camera pos
  21.   glLoadIdentity;
  22.   glLoadmatrixd(@matM);
  23.  
  24.   //mirror it
  25.   glScalef(1.0, 1.0, -1.0);
  26.  
  27.   //enable clipping plane
  28.   glClipPlane(GL_CLIP_PLANE0, @CP);
  29.   glEnable(GL_CLIP_PLANE0);
  30.  
  31.   //translate the mirror from its position back to 0
  32.   //actualy the scene is rotated with the reverse matrix of the mirror?
  33.   glrotatef(-mirrorrot.y,0,1,0);
  34.   glrotatef(-mirrorrot.x,1,0,0);
  35.   glrotatef(-mirrorrot.z,0,0,1);
  36.   gltranslatef(-mirrorpos.x,-mirrorpos.y,-mirrorpos.z);
  37.  
  38.   //draw the scene...
  39.   DrawObjects;
  40.  
  41.   //disable the clipping plane
  42.   glDisable(GL_CLIP_PLANE0);
  43.  
  44.   //copy the color buffer to a texture creating a new texture if necessary
  45.   if (Reflection <> 0) then
  46.   begin
  47.     glBindTexture(GL_TEXTURE_2D, Reflection);
  48.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
  49.       GL_LINEAR);
  50.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
  51.       GL_LINEAR);
  52.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
  53.       GL_CLAMP);
  54.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
  55.       GL_CLAMP);
  56.     glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0,
  57.       M_SIZE, M_SIZE);
  58.   end else
  59.   begin
  60.     glGenTextures(1, @Reflection);
  61.     glBindTexture(GL_TEXTURE_2D, Reflection);
  62.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
  63.       GL_LINEAR);
  64.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
  65.       GL_LINEAR);
  66.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
  67.       GL_CLAMP);
  68.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
  69.       GL_CLAMP);
  70.     glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0,
  71.       M_SIZE, M_SIZE, 0);
  72.   end;
  73.  
  74.   //restore the viewport
  75.   glViewport(0, 0, WND_XSIZE, WND_YSIZE);
  76. end;
  77.  
  78. //calculate the texture coordinates for a vertex and send them to OpenGL
  79. procedure RenderVertex(vX, vY, vZ: Single);
  80. var
  81.   tX, tY, tZ: Double;
  82. const
  83.   vp: TGLVectori4 = (0,0,1,1); //dummy viewport
  84. begin
  85.   //calculate the window coordinates of the vertex
  86.   gluProject(vX, vY, vZ, matM, matP, vp, @tX, @tY, @tZ);
  87.   //use the window coords as texture coords
  88.   glTexCoord2f(tX, tY);
  89.   glVertex3f(vX, vY, vZ);
  90. end;
  91.  
  92. //  Function to draw the actual scene
  93. procedure glDraw();
  94. var
  95.  i,j: integer;
  96. begin
  97.  
  98.  Time := GetTickCount / 1000.0;
  99.  
  100.  //set mirror pos...
  101.  mirrorpos.x:=Sin(Time * 1.3);
  102.  mirrorpos.y:=Sin(Time * 1.3);
  103.  mirrorpos.z:=Sin(Time * 1.3);
  104.  
  105.  mirrorrot.x:=Sin(Time * 1.3) * 60;
  106.  mirrorrot.y:=Sin(Time * 1.4) * 60;
  107.  mirrorrot.z:=Sin(Time * 1.5) * 60;
  108.  
  109.  glLoadIdentity;
  110.  
  111.  //set camera pos...
  112.  gltranslatef(0,-5,-20);
  113.  glrotatef(10,1,0,0);
  114.  
  115.  //Get the modelview and projection matrices
  116.  glGetDoublev(GL_MODELVIEW_MATRIX, @matM);
  117.  glGetDoublev(GL_PROJECTION_MATRIX, @matP);
  118.  
  119.  CreateTexture; //create the mirror texture
  120.  
  121.  glClearColor(0.0, 0.0, 0.2, 0.0);        //  Background color
  122.  glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); //comment this line out the see the last renderend mirror scene
  123.  glLoadIdentity();
  124.  glLoadmatrixD(@matM);
  125.  
  126.  glLightfv(GL_LIGHT0, GL_POSITION, @lp); //position light
  127.  
  128.  //render the mirror
  129.  glColor4f(1, 1, 1, 0.5); // make the water transparent.
  130.  gldisable(GL_LIGHTING);
  131.  glenable(GL_TEXTURE_2D);
  132.  glBindTexture(GL_TEXTURE_2D, Reflection); //use calculated mirror texture
  133.  glpushmatrix();
  134.   //place the mirror
  135.   gltranslatef(mirrorpos.x,mirrorpos.y,mirrorpos.z);
  136.   glrotatef(mirrorrot.z,0,0,1);
  137.   glrotatef(mirrorrot.x,1,0,0);
  138.   glrotatef(mirrorrot.y,0,1,0);
  139.  
  140.   //do the actual rendering
  141.   //by using RenderVertex the texture coords are recalculated
  142.   for I := -(mirrorsize div 2) to (mirrorsize div 2) - 1 do
  143.    begin
  144.     glBegin(GL_QUAD_STRIP);
  145.     for J := -(mirrorsize div 2) to (mirrorsize div 2) do
  146.     begin
  147.       RenderVertex(I / M_DETAIL - 0.5,
  148.         J / M_DETAIL - 0.5, 0.0);
  149.       RenderVertex((I + 1) / M_DETAIL - 0.5,
  150.         J / M_DETAIL - 0.5, 0.0);
  151.     end;
  152.     glEnd;
  153.  
  154.    end;
  155.  glpopmatrix();
  156.  gldisable(GL_TEXTURE_2D);
  157.  glenable(GL_LIGHTING);
  158.  
  159.  //draw the scene...
  160.  drawobjects();
  161.  
  162.  // Flush the OpenGL Buffer
  163.  glFlush();
  164.  
  165. end;
  166.  
[/code]

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 14 Beiträge ] 
Foren-Übersicht » Programmierung » OpenGL


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 12 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.011s | 15 Queries | GZIP : On ]