I am writing an application in which at the moment you need to integrate the particle system. I have a suitable thing - Magic Particles from Astralax. I have ported the functionality of this library to myself but the drawing of the final result does not work for me. I do not understand what the problem is. Either the context does not work for me correctly, or I missed some step. You can see and run the project yourself. m_paintDevice-> update () method; just causes glDrawElements and it works, but the result is not visible. What could be the problem?

The code on github .

mainwidget.cpp

void MainWidget::initializeGL() { makeCurrent(); initializeOpenGLFunctions(); glClearColor(0, 0, 0, 1); m_paintDevice = new PaintDevice(this->width(), this->height()); timer.start(12, this); } void MainWidget::timerEvent(QTimerEvent *e) { m_paintDevice->update(); update(); } void MainWidget::paintGL() { glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_paintDevice->paint(); QCoreApplication::postEvent(this, new QEvent(QEvent::UpdateRequest)); } 

mp_wrap.cpp

 void MP_Device_WRAP::DrawVertices(int starting_index, int indexes_count, int max_vertices) { MP_BUFFER_RAM *index_buffer_ram = (MP_BUFFER_RAM *)index_buffer; #ifdef INDEX_BUFFER_32_WRAP glDrawElements(GL_TRIANGLES, indexes_count, GL_UNSIGNED_INT, &(index_buffer_ram->buffer[starting_index * 4])); #else glDrawElements(GL_TRIANGLES, indexes_count, GL_UNSIGNED_SHORT, &(index_buffer_ram->buffer[starting_index * 2])); #endif } 

    1 answer 1

    I found a solution - everything was connected with the shader that came in the kit, I began to conjure with its settings and everything worked for me, more precisely at the moment everything is drawn in green.

    The gl_FragColor parameter of the shader in the system is specified as the sum of the color of the particle and the texture.

     void main() { vec4 color; vec4 arg1; vec4 arg2; vec4 colorTex; colorTex = texture2D(texture0, textureCoordinate0); arg1 = colorVarying; arg2 = colorTex; color = arg1 * arg2; gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); //gl_FragColor = color; 

    }

    The commented out part of the code is the default shader line. I replaced the color for the experiment and saw the particles being drawn. After that (for several days) I started the texture work itself, by transferring all the functionality for working with textures from wrappers to QOpenGLTexture.

    This is the result of what happened after replacing the color in the shader (more precisely, with the parameter set gl_FragColor = colorVarying;

    one

    After I started the texture work and restored the shader to the original parameters, I got the following result:

    2

    And the final result should look like this:

    3

    But at the moment I have difficulties in the final realization of this effect. This is connected either with mixing or with the incorrect operation of the color scheme (alpha channel), but this no longer applies to this post. Thank.

    • Describe in the answer in detail what settings you set - Kostiantyn Okhotnyk
    • Unsubscribed, thanks for the help. - iMashine