Example Texturing - MrShoor/AvalancheProject GitHub Wiki

Path:

\Avalanche\Demos\Src\Texturing

Initialization

The following objects are needed for rendering a texture cube

  • FMain: TavMainRender - the core object for 3d rendering
  • FProgram: TavProgram - shared program object that performs drawing of 3d-data
  • FCubeVertices: TavVB - vertex information of 3d-data
  • FCubeIndices: TavIB - indices (faces/polygon) information data of 3d-data
  • FTexture: TavTexture - texture object containing bitmap information for rending
  • FFrameBuffer: TavFrameBuffer - frame buffer object - the target for rendering and later presence on the window

Allocate a rendered

Initialization of the renderer, binding to a window. (Handle in this case is Win32 HWND object). Init3D() - initialized a 3d graphics (defaulting to OpenGL, since not specified explicitly)

FMain := TavMainRender.Create(Nil);
FMain.Window := Handle;
FMain.Init3D();

Camera and projection is setup to show the cube nicely

FMain.Camera.Eye := Vec(-1.6, 1.4,-2.0);
FMain.Projection.FarPlane := 10.0;
FMain.Projection.NearPlane := 0.1;  

Allocate a frame buffer

Framebuffer is allocated with 32-bit color with 32-float depth

FFrameBuffer := Create_FrameBuffer(FMain, [TTextureFormat.RGBA, TTextureFormat.D32f]);

Allocate program

Allocating program object and loading from resource named 'base'

FProgram := TavProgram.Create(FMain);
FProgram.Load('base', True);

Create and load texture

FTexture := TavTexture.Create(FMain);
FTexture.TargetFormat := TTextureFormat.RGBA;
FTexture.AutoGenerateMips := True;
FTexture.TexData := LoadTexture('..\Media\tig.jpg',
    SIZE_DEFAULT, SIZE_DEFAULT, TImageFormat.A8R8G8B8);

Generate vertex information

GenCube(H, H, H, 1, 1, vert, ind);

FCubeVertices := TavVB.Create(FMain);
FCubeVertices.Vertices := vert;
FCubeIndices := TavIB.Create(FMain);
FCubeIndices.PrimType := ptTriangles;
FCubeIndices.Indices := ind;
FCubeIndices.CullMode := cmNone;

Initialize camera controller

cc := TavCameraController.Create(FMain);
cc.CanRotate := True;

The allocated controller would accept the mouse input messages and adjust camera position accordingly

Rendering