MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / paintGL

Method paintGL

compute/example/resize_image.cpp:162–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

160}
161
162void ImageWidget::paintGL()
163{
164 float w = width();
165 float h = height();
166
167 glMatrixMode(GL_PROJECTION);
168 glLoadIdentity();
169 glOrtho(0.0, w, 0.0, h, -1.0, 1.0);
170 glMatrixMode(GL_MODELVIEW);
171 glLoadIdentity();
172
173 // setup the resize kernel
174 compute::kernel kernel(program_, "resize_image");
175 kernel.set_arg(0, image_);
176 kernel.set_arg(1, sampler_);
177 kernel.set_arg(2, cl_texture_);
178
179 // acquire the opengl texture so it can be used in opencl
180 compute::opengl_enqueue_acquire_gl_objects(1, &cl_texture_.get(), queue_);
181
182 // execute the resize kernel
183 const size_t global_work_offset[] = { 0, 0 };
184 const size_t global_work_size[] = { size_t(width()), size_t(height()) };
185
186 queue_.enqueue_nd_range_kernel(
187 kernel, 2, global_work_offset, global_work_size, 0
188 );
189
190 // release the opengl texture so it can be used by opengl
191 compute::opengl_enqueue_release_gl_objects(1, &cl_texture_.get(), queue_);
192
193 // ensure opencl is finished before rendering in opengl
194 queue_.finish();
195
196 // draw a single quad with the resized image texture
197 glEnable(GL_TEXTURE_2D);
198 glBindTexture(GL_TEXTURE_2D, gl_texture_);
199
200 glBegin(GL_QUADS);
201 glTexCoord2f(0, 0); glVertex2f(0, 0);
202 glTexCoord2f(0, 1); glVertex2f(0, h);
203 glTexCoord2f(1, 1); glVertex2f(w, h);
204 glTexCoord2f(1, 0); glVertex2f(w, 0);
205 glEnd();
206}
207
208// the resize image example demonstrates how to interactively resize a
209// 2D image and display it using OpenGL. a image sampler is used to perform

Callers

nothing calls this directly

Calls 6

set_argMethod · 0.45
getMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected