TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ Bake()

void TextureBaker::Bake ( )
private

Definition at line 102 of file TextureBaker.cpp.

103{
104 if(bakeFrameBuffer != nullptr)
105 {
106 delete bakeFrameBuffer;
107 }
108
109 if(useTiledExport)
110 {
111 std::string path = ShowSaveFileDialog(".png");
112 if(path.size() <= 3)
113 return;
114 std::string nameBase = "";
115 if(path.find_last_of(".png") == std::string::npos)
116 nameBase = path;
117 else
118 nameBase = path.substr(0, path.find_last_of(".png"));
119
120 if(tileCount < 0)
121 tileCount = -1 * tileCount;
122 if(tileCount == 0)
123 tileCount = 2;
124 if(tileCount % 2 != 0)
125 tileCount += 1;
126
127
128 bakeFrameBuffer = new FrameBuffer(tileResolution, tileResolution);
129
130 std::cout << "Starting to render tiles." << std::endl;
131 for(int i = -1 * tileCount + 1 ; i <= tileCount - 1 ; i+= 2)
132 {
133 for(int j = -1 * tileCount + 1 ; j <= tileCount - 1 ; j+= 2)
134 {
135 tileY = i;
136 tileX = j;
137 std::cout << "Rendering Tile : " << (i + tileCount) << ", " << (j + tileCount) << "\r";
138 bakeFrameBuffer->Begin();
139 glViewport(0, 0, tileResolution, tileResolution);
140 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
141 Render(false);
142 ExportTexture(bakeFrameBuffer->GetRendererID(), nameBase + "_" + std::to_string((i + tileCount)/2) + "_" + std::to_string((j + tileCount)/2) + ".png", tileResolution, tileResolution);
143 std::cout << "Rendered Tile : " << (i + tileCount) / 2 << ", " << (j + tileCount) / 2 << " to " << (nameBase + "_" + std::to_string((i + tileCount)/2) + "_" + std::to_string((j + tileCount)/2) + ".png") << std::endl;
144 }
145
146 }
147
148 glBindFramebuffer(GL_FRAMEBUFFER, 0);
149 delete bakeFrameBuffer;
150 bakeFrameBuffer = nullptr;
151 }
152 else
153 {
154 std::string path = ShowSaveFileDialog(".png");
155 if(path.size() <= 3)
156 return;
157 bakeFrameBuffer = new FrameBuffer(tileResolution, tileResolution);
158 bakeFrameBuffer->Begin();
159 glViewport(0, 0, tileResolution, tileResolution);
160 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
161 Render(false);
162 ExportTexture(bakeFrameBuffer->GetRendererID(), path, tileResolution, tileResolution);
163 glBindFramebuffer(GL_FRAMEBUFFER, 0);
164 delete bakeFrameBuffer;
165 bakeFrameBuffer = nullptr;
166 }
167}