-
Notifications
You must be signed in to change notification settings - Fork 3
Example Texturing
Dmitry Boyarintsev edited this page Oct 2, 2017
·
9 revisions
Path:
\Avalanche\Demos\Src\Texturing
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
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;
Framebuffer is allocated with 32-bit color with 32-float depth
FFrameBuffer := Create_FrameBuffer(FMain, [TTextureFormat.RGBA, TTextureFormat.D32f]);
Allocating program object and loading from resource named 'base'
FProgram := TavProgram.Create(FMain);
FProgram.Load('base', True);
FTexture := TavTexture.Create(FMain);
FTexture.TargetFormat := TTextureFormat.RGBA;
FTexture.AutoGenerateMips := True;
FTexture.TexData := LoadTexture('..\Media\tig.jpg',
SIZE_DEFAULT, SIZE_DEFAULT, TImageFormat.A8R8G8B8);
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;
cc := TavCameraController.Create(FMain);
cc.CanRotate := True;
The allocated controller would accept the mouse input messages and adjust camera position accordingly