MCPcopy Create free account
hub / github.com/davideberly/GeometricTools / CreateScene

Method CreateScene

GTE/Samples/Graphics/Texturing/TexturingWindow3.cpp:74–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72}
73
74void TexturingWindow3::CreateScene()
75{
76 // Create a vertex buffer for a two-triangles square. The PNG is stored
77 // in left-handed coordinates. The texture coordinates are chosen to
78 // reflect the texture in the y-direction.
79 struct Vertex
80 {
81 Vector3<float> position;
82 Vector2<float> tcoord;
83 };
84
85 VertexFormat vformat;
86 vformat.Bind(VASemantic::POSITION, DF_R32G32B32_FLOAT, 0);
87 vformat.Bind(VASemantic::TEXCOORD, DF_R32G32_FLOAT, 0);
88
89 auto vbuffer = std::make_shared<VertexBuffer>(vformat, 4);
90 auto* vertices = vbuffer->Get<Vertex>();
91 vertices[0].position = { 0.0f, 0.0f, 0.0f };
92 vertices[0].tcoord = { 0.0f, 1.0f };
93 vertices[1].position = { 1.0f, 0.0f, 0.0f };
94 vertices[1].tcoord = { 1.0f, 1.0f };
95 vertices[2].position = { 0.0f, 1.0f, 0.0f };
96 vertices[2].tcoord = { 0.0f, 0.0f };
97 vertices[3].position = { 1.0f, 1.0f, 0.0f };
98 vertices[3].tcoord = { 1.0f, 0.0f };
99
100 // Create an indexless buffer for a triangle mesh with two triangles.
101 auto ibuffer = std::make_shared<IndexBuffer>(IP_TRISTRIP, 2);
102
103 // Create an effect for the vertex and pixel shaders. The texture is
104 // bilinearly filtered and the texture coordinates are clamped to [0,1]^2.
105 auto myTexture = WICFileIO::Load(mEnvironment.GetPath("StoneWall.png"), false);
106 auto effect = std::make_shared<Texture2Effect>(mProgramFactory, myTexture,
107 SamplerState::Filter::MIN_L_MAG_L_MIP_P, SamplerState::Mode::CLAMP, SamplerState::Mode::CLAMP);
108
109 // Create the geometric object for drawing. Translate it so that its
110 // center of mass is at the origin. This supports virtual trackball
111 // motion about the object "center".
112 mSquare = std::make_shared<Visual>(vbuffer, ibuffer, effect);
113 mSquare->localTransform.SetTranslation(-0.5f, -0.5f, 0.0f);
114
115 // Enable automatic updates of pvw-matrices and w-matrices.
116 mPVWMatrices.Subscribe(mSquare->worldTransform, effect->GetPVWMatrixConstant());
117
118#if defined(SAVE_RENDERING_TO_DISK)
119 mTarget = std::make_shared<DrawTarget>(1, DF_R8G8B8A8_UNORM, mXSize,
120 mYSize);
121 mTarget->GetRTTexture(0)->SetCopy(Resource::Copy::STAGING_TO_CPU);
122#endif
123
124 mTrackBall.Attach(mSquare);
125 mTrackBall.Update();
126}
127
128

Callers

nothing calls this directly

Calls 8

GetPathMethod · 0.80
SetTranslationMethod · 0.80
SubscribeMethod · 0.80
SetCopyMethod · 0.80
AttachMethod · 0.80
BindMethod · 0.45
GetRTTextureMethod · 0.45
UpdateMethod · 0.45

Tested by

no test coverage detected