opengl: Work on multi-texturing.
This commit is contained in:
@@ -76,6 +76,9 @@ begin
|
|||||||
Demo.Renderer.set (the_Light);
|
Demo.Renderer.set (the_Light);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
-- openGL.Demo.Camera.allow_Impostors;
|
||||||
|
|
||||||
|
|
||||||
-- Main loop.
|
-- Main loop.
|
||||||
--
|
--
|
||||||
while not Demo.Done
|
while not Demo.Done
|
||||||
|
|||||||
@@ -3,9 +3,12 @@ with
|
|||||||
openGL.Visual,
|
openGL.Visual,
|
||||||
openGL.Light,
|
openGL.Light,
|
||||||
openGL.Palette,
|
openGL.Palette,
|
||||||
|
openGL.Geometry.texturing,
|
||||||
-- openGL.IO,
|
-- openGL.IO,
|
||||||
openGL.Demo;
|
openGL.Demo;
|
||||||
|
|
||||||
|
with Ada.Text_IO; use Ada.Text_IO;
|
||||||
|
|
||||||
|
|
||||||
procedure launch_render_two_Textures
|
procedure launch_render_two_Textures
|
||||||
--
|
--
|
||||||
@@ -22,8 +25,9 @@ is
|
|||||||
--------------
|
--------------
|
||||||
-- The model.
|
-- The model.
|
||||||
--
|
--
|
||||||
the_1st_Texture : constant asset_Name := to_Asset ("assets/opengl/texture/blobber_floor.png");
|
-- the_1st_Texture : constant asset_Name := to_Asset ("assets/opengl/texture/blobber_floor.png");
|
||||||
the_2nd_Texture : constant asset_Name := to_Asset ("assets/opengl/texture/crawl_blob-1.png");
|
the_1st_Texture : constant asset_Name := to_Asset ("assets/crawl-blob-1.png");
|
||||||
|
the_2nd_Texture : constant asset_Name := to_Asset ("assets/crawl-blob-2.png");
|
||||||
|
|
||||||
the_textured_hexagon_Model : constant Model.hexagon.lit_textured_x2.view
|
the_textured_hexagon_Model : constant Model.hexagon.lit_textured_x2.view
|
||||||
:= Model.hexagon.lit_textured_x2.new_Hexagon (Radius => 0.5,
|
:= Model.hexagon.lit_textured_x2.new_Hexagon (Radius => 0.5,
|
||||||
@@ -45,6 +49,11 @@ is
|
|||||||
light_Site : constant openGL.Vector_3 := [0.0, 0.0, 15.0];
|
light_Site : constant openGL.Vector_3 := [0.0, 0.0, 15.0];
|
||||||
cone_Direction : constant openGL.Vector_3 := [0.0, 0.0, -1.0];
|
cone_Direction : constant openGL.Vector_3 := [0.0, 0.0, -1.0];
|
||||||
|
|
||||||
|
use openGL.Geometry.texturing;
|
||||||
|
Fade : fade_Level := fade_Level'First;
|
||||||
|
increment_Fade : Boolean := True;
|
||||||
|
Epoch : Natural := 0;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Demo.print_Usage;
|
Demo.print_Usage;
|
||||||
Demo.define ("openGL 'render two Textures' Demo",
|
Demo.define ("openGL 'render two Textures' Demo",
|
||||||
@@ -82,6 +91,34 @@ begin
|
|||||||
|
|
||||||
Demo.Renderer.render;
|
Demo.Renderer.render;
|
||||||
Demo.FPS_Counter.increment; -- Frames per second display.
|
Demo.FPS_Counter.increment; -- Frames per second display.
|
||||||
|
|
||||||
|
|
||||||
|
if Epoch mod 20 = 0
|
||||||
|
then
|
||||||
|
the_textured_hexagon_Model.Fade_1_is (Fade);
|
||||||
|
the_textured_hexagon_Model.Fade_2_is (1.0 - Fade);
|
||||||
|
-- the_textured_hexagon_Model.needs_Rebuild;
|
||||||
|
--
|
||||||
|
-- the_textured_hexagon_Model.Fade_1_is (1.0);
|
||||||
|
-- the_textured_hexagon_Model.Fade_2_is (0.0);
|
||||||
|
|
||||||
|
-- put_Line ("my Fade: " & Fade'Image);
|
||||||
|
|
||||||
|
if increment_Fade
|
||||||
|
then
|
||||||
|
Fade := Fade + fade_Level'Small;
|
||||||
|
else
|
||||||
|
Fade := Fade - fade_Level'Small;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
if Fade = fade_Level'Last then increment_Fade := False;
|
||||||
|
elsif Fade = fade_Level'First then increment_Fade := True;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
end if;
|
||||||
|
|
||||||
|
Epoch := Epoch + 1;
|
||||||
end loop;
|
end loop;
|
||||||
|
|
||||||
Demo.destroy;
|
Demo.destroy;
|
||||||
end launch_render_two_Textures;
|
end launch_render_two_Textures;
|
||||||
|
|||||||
@@ -13,8 +13,14 @@ apply_Texturing (vec2 Coords)
|
|||||||
* texture (Textures [i], Coords).a
|
* texture (Textures [i], Coords).a
|
||||||
* (1.0 - Fade [i]);
|
* (1.0 - Fade [i]);
|
||||||
|
|
||||||
Color.a = max (Color.a, texture (Textures [i],
|
// Color.a += texture (Textures [i], Coords).a * (1.0 - Fade[1]);
|
||||||
Coords).a);
|
|
||||||
|
Color.a = max (Color.a,
|
||||||
|
texture (Textures [i],Coords).a * (1.0 - Fade[i]));
|
||||||
|
|
||||||
|
|
||||||
|
// Color.a = max (Color.a,
|
||||||
|
// texture (Textures [i],Coords).a);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Color;
|
return Color;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ with
|
|||||||
openGL.Attribute,
|
openGL.Attribute,
|
||||||
openGL.Texture,
|
openGL.Texture,
|
||||||
openGL.Palette,
|
openGL.Palette,
|
||||||
|
openGL.Model,
|
||||||
openGL.Tasks,
|
openGL.Tasks,
|
||||||
openGL.Errors,
|
openGL.Errors,
|
||||||
|
|
||||||
@@ -312,6 +313,10 @@ is
|
|||||||
is
|
is
|
||||||
use openGL.Geometry.texturing;
|
use openGL.Geometry.texturing;
|
||||||
begin
|
begin
|
||||||
|
Self.Textures.Textures (1).Fade := Self.Model.Fade_1;
|
||||||
|
Self.Textures.Textures (2).Fade := Self.Model.Fade_2;
|
||||||
|
|
||||||
|
|
||||||
enable (Self.Textures, Self.Program);
|
enable (Self.Textures, Self.Program);
|
||||||
end enable_Texture;
|
end enable_Texture;
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ with
|
|||||||
|
|
||||||
ada.Strings.fixed;
|
ada.Strings.fixed;
|
||||||
|
|
||||||
|
with ada.Text_IO; use ada.Text_IO;
|
||||||
|
|
||||||
|
|
||||||
package body openGL.Geometry.texturing
|
package body openGL.Geometry.texturing
|
||||||
is
|
is
|
||||||
@@ -156,6 +158,8 @@ is
|
|||||||
uniform_Name : constant String := "Fade[" & Trim (Natural'Image (i - 1), Left) & "]";
|
uniform_Name : constant String := "Fade[" & Trim (Natural'Image (i - 1), Left) & "]";
|
||||||
Uniform : constant openGL.Variable.uniform.float := Program.uniform_Variable (uniform_Name);
|
Uniform : constant openGL.Variable.uniform.float := Program.uniform_Variable (uniform_Name);
|
||||||
begin
|
begin
|
||||||
|
-- put_Line ("Fade:" & the_Textures.Textures (texture_Id (i)).Fade'Image);
|
||||||
|
|
||||||
Uniform.Value_is (Real (the_Textures.Textures (texture_Id (i)).Fade));
|
Uniform.Value_is (Real (the_Textures.Textures (texture_Id (i)).Fade));
|
||||||
end;
|
end;
|
||||||
end loop;
|
end loop;
|
||||||
|
|||||||
@@ -50,6 +50,15 @@ is
|
|||||||
-- Attributes
|
-- Attributes
|
||||||
--
|
--
|
||||||
|
|
||||||
|
procedure Model_is (Self : in out Item; Now : in Model_view)
|
||||||
|
is
|
||||||
|
begin
|
||||||
|
Self.Model := Now;
|
||||||
|
end Model_is;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function Label (Self : in Item'Class) return String
|
function Label (Self : in Item'Class) return String
|
||||||
is
|
is
|
||||||
begin
|
begin
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ with
|
|||||||
openGL.Program,
|
openGL.Program,
|
||||||
openGL.Texture;
|
openGL.Texture;
|
||||||
|
|
||||||
|
limited
|
||||||
|
with
|
||||||
|
openGL.Model;
|
||||||
|
|
||||||
private
|
private
|
||||||
with
|
with
|
||||||
@@ -38,6 +41,11 @@ is
|
|||||||
-- Attributes
|
-- Attributes
|
||||||
--
|
--
|
||||||
|
|
||||||
|
type Model_view is access all openGL.Model.item'Class;
|
||||||
|
|
||||||
|
procedure Model_is (Self : in out Item; Now : in Model_view);
|
||||||
|
|
||||||
|
|
||||||
procedure Label_is (Self : in out Item'Class; Now : in String);
|
procedure Label_is (Self : in out Item'Class; Now : in String);
|
||||||
function Label (Self : in Item'Class) return String;
|
function Label (Self : in Item'Class) return String;
|
||||||
|
|
||||||
@@ -90,16 +98,16 @@ is
|
|||||||
Sites : in openGL.Sites) return access Normals;
|
Sites : in openGL.Sites) return access Normals;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
use ada.Strings.unbounded;
|
use ada.Strings.unbounded;
|
||||||
|
|
||||||
type Textures is array (texture_Id) of openGL.Texture.Object;
|
type Textures is array (texture_Id) of openGL.Texture.Object;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
type Item is abstract tagged limited
|
type Item is abstract tagged limited
|
||||||
record
|
record
|
||||||
|
Model : Model_view;
|
||||||
Label : unbounded_String;
|
Label : unbounded_String;
|
||||||
Program : openGL.Program.view;
|
Program : openGL.Program.view;
|
||||||
Vertices : Buffer.view;
|
Vertices : Buffer.view;
|
||||||
|
|||||||
@@ -27,23 +27,6 @@ is
|
|||||||
--- Attributes
|
--- Attributes
|
||||||
--
|
--
|
||||||
|
|
||||||
procedure Texture_1_is (Self : in out Item; Now : in openGL.asset_Name)
|
|
||||||
is
|
|
||||||
begin
|
|
||||||
Self.Face.Texture_1 := Now;
|
|
||||||
end Texture_1_is;
|
|
||||||
|
|
||||||
|
|
||||||
procedure Texture_2_is (Self : in out Item; Now : in openGL.asset_Name)
|
|
||||||
is
|
|
||||||
begin
|
|
||||||
Self.Face.Texture_2 := Now;
|
|
||||||
end Texture_2_is;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
overriding
|
overriding
|
||||||
function to_GL_Geometries (Self : access Item; Textures : access Texture.name_Map_of_texture'Class;
|
function to_GL_Geometries (Self : access Item; Textures : access Texture.name_Map_of_texture'Class;
|
||||||
Fonts : in Font.font_id_Map_of_font) return Geometry.views
|
Fonts : in Font.font_id_Map_of_font) return Geometry.views
|
||||||
@@ -116,8 +99,66 @@ is
|
|||||||
upper_Face := new_Face (Vertices => the_Vertices);
|
upper_Face := new_Face (Vertices => the_Vertices);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
upper_Face.Model_is (Self.all'unchecked_Access);
|
||||||
|
|
||||||
return (1 => upper_Face.all'Access);
|
return (1 => upper_Face.all'Access);
|
||||||
end to_GL_Geometries;
|
end to_GL_Geometries;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
------------
|
||||||
|
-- Texturing
|
||||||
|
--
|
||||||
|
|
||||||
|
procedure Texture_1_is (Self : in out Item; Now : in openGL.asset_Name)
|
||||||
|
is
|
||||||
|
begin
|
||||||
|
Self.Face.Texture_1 := Now;
|
||||||
|
end Texture_1_is;
|
||||||
|
|
||||||
|
|
||||||
|
procedure Texture_2_is (Self : in out Item; Now : in openGL.asset_Name)
|
||||||
|
is
|
||||||
|
begin
|
||||||
|
Self.Face.Texture_2 := Now;
|
||||||
|
end Texture_2_is;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
overriding
|
||||||
|
procedure Fade_1_is (Self : in out Item; Now : in openGL.Geometry.texturing.fade_Level)
|
||||||
|
is
|
||||||
|
begin
|
||||||
|
Self.Face.Fade_1 := Now;
|
||||||
|
end Fade_1_is;
|
||||||
|
|
||||||
|
|
||||||
|
overriding
|
||||||
|
procedure Fade_2_is (Self : in out Item; Now : in openGL.Geometry.texturing.fade_Level)
|
||||||
|
is
|
||||||
|
begin
|
||||||
|
Self.Face.Fade_2 := Now;
|
||||||
|
end Fade_2_is;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
overriding
|
||||||
|
function Fade_1 (Self : in Item) return Geometry.Texturing.fade_Level
|
||||||
|
is
|
||||||
|
begin
|
||||||
|
return Self.Face.Fade_1;
|
||||||
|
end Fade_1;
|
||||||
|
|
||||||
|
|
||||||
|
overriding
|
||||||
|
function Fade_2 (Self : in Item) return Geometry.Texturing.fade_Level
|
||||||
|
is
|
||||||
|
begin
|
||||||
|
return Self.Face.Fade_2;
|
||||||
|
end Fade_2;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end openGL.Model.hexagon.lit_textured_x2;
|
end openGL.Model.hexagon.lit_textured_x2;
|
||||||
|
|||||||
@@ -32,13 +32,32 @@ is
|
|||||||
--- Attributes
|
--- Attributes
|
||||||
--
|
--
|
||||||
|
|
||||||
|
overriding
|
||||||
|
function to_GL_Geometries (Self : access Item; Textures : access Texture.name_Map_of_texture'Class;
|
||||||
|
Fonts : in Font.font_id_Map_of_font) return Geometry.views;
|
||||||
|
|
||||||
|
|
||||||
|
------------
|
||||||
|
-- Texturing
|
||||||
|
--
|
||||||
|
|
||||||
procedure Texture_1_is (Self : in out Item; Now : in openGL.asset_Name);
|
procedure Texture_1_is (Self : in out Item; Now : in openGL.asset_Name);
|
||||||
procedure Texture_2_is (Self : in out Item; Now : in openGL.asset_Name);
|
procedure Texture_2_is (Self : in out Item; Now : in openGL.asset_Name);
|
||||||
|
|
||||||
|
|
||||||
overriding
|
overriding
|
||||||
function to_GL_Geometries (Self : access Item; Textures : access Texture.name_Map_of_texture'Class;
|
procedure Fade_1_is (Self : in out Item; Now : in openGL.Geometry.texturing.fade_Level);
|
||||||
Fonts : in Font.font_id_Map_of_font) return Geometry.views;
|
|
||||||
|
overriding
|
||||||
|
procedure Fade_2_is (Self : in out Item; Now : in openGL.Geometry.texturing.fade_Level);
|
||||||
|
|
||||||
|
|
||||||
|
overriding
|
||||||
|
function Fade_1 (Self : in Item) return Geometry.Texturing.fade_Level;
|
||||||
|
|
||||||
|
overriding
|
||||||
|
function Fade_2 (Self : in Item) return Geometry.Texturing.fade_Level;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -211,4 +211,44 @@ is
|
|||||||
Self.needs_Rebuild := True;
|
Self.needs_Rebuild := True;
|
||||||
end needs_Rebuild;
|
end needs_Rebuild;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
------------
|
||||||
|
-- Texturing
|
||||||
|
--
|
||||||
|
|
||||||
|
procedure Fade_1_is (Self : in out Item; Now : in Geometry.Texturing.fade_Level)
|
||||||
|
is
|
||||||
|
begin
|
||||||
|
raise program_Error with "Model does not support texturing.";
|
||||||
|
end Fade_1_is;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
procedure Fade_2_is (Self : in out Item; Now : in Geometry.Texturing.fade_Level)
|
||||||
|
is
|
||||||
|
begin
|
||||||
|
raise program_Error with "Model does not support texturing.";
|
||||||
|
end Fade_2_is;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function Fade_1 (Self : in Item) return Geometry.Texturing.fade_Level
|
||||||
|
is
|
||||||
|
begin
|
||||||
|
raise program_Error with "Model does not support texturing.";
|
||||||
|
return 0.0;
|
||||||
|
end Fade_1;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function Fade_2 (Self : in Item) return Geometry.Texturing.fade_Level
|
||||||
|
is
|
||||||
|
begin
|
||||||
|
raise program_Error with "Model does not support texturing.";
|
||||||
|
return 0.0;
|
||||||
|
end Fade_2;
|
||||||
|
|
||||||
|
|
||||||
end openGL.Model;
|
end openGL.Model;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ with
|
|||||||
openGL.remote_Model,
|
openGL.remote_Model,
|
||||||
openGL.Font,
|
openGL.Font,
|
||||||
openGL.Texture,
|
openGL.Texture,
|
||||||
openGL.Geometry;
|
openGL.Geometry.texturing;
|
||||||
|
|
||||||
|
|
||||||
package openGL.Model
|
package openGL.Model
|
||||||
@@ -68,6 +68,19 @@ is
|
|||||||
Fonts : in Font.font_id_Map_of_font);
|
Fonts : in Font.font_id_Map_of_font);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
------------
|
||||||
|
-- Texturing
|
||||||
|
--
|
||||||
|
|
||||||
|
procedure Fade_1_is (Self : in out Item; Now : in Geometry.Texturing.fade_Level);
|
||||||
|
procedure Fade_2_is (Self : in out Item; Now : in Geometry.Texturing.fade_Level);
|
||||||
|
|
||||||
|
function Fade_1 (Self : in Item) return Geometry.Texturing.fade_Level;
|
||||||
|
function Fade_2 (Self : in Item) return Geometry.Texturing.fade_Level;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
type Item is abstract new remote_Model.item with
|
type Item is abstract new remote_Model.item with
|
||||||
|
|||||||
@@ -549,6 +549,7 @@ is
|
|||||||
and the_Visual.Model. lucid_Geometries = null)
|
and the_Visual.Model. lucid_Geometries = null)
|
||||||
then
|
then
|
||||||
the_Visual.Model.create_GL_Geometries (Self.Textures'Access, Self.Fonts);
|
the_Visual.Model.create_GL_Geometries (Self.Textures'Access, Self.Fonts);
|
||||||
|
-- put_Line ("Rebuild");
|
||||||
|
|
||||||
elsif the_Visual.Model.is_Modified
|
elsif the_Visual.Model.is_Modified
|
||||||
then
|
then
|
||||||
|
|||||||
Reference in New Issue
Block a user