Ejemplo n.º 1
0
void MainLoop(){
#if _WIN32
	RunCuda();

	glBindBuffer(GL_PIXEL_UNPACK_BUFFER, m_pbo);
    glBindTexture(GL_TEXTURE_2D, m_image);
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_width, m_height, GL_RGBA, 
                        GL_UNSIGNED_BYTE, NULL);
    glClear(GL_COLOR_BUFFER_BIT);   

    // VAO, shader program, and texture already bound
    glDrawElements(GL_TRIANGLES, 6,  GL_UNSIGNED_SHORT, 0);
	glutSwapBuffers();
#else
    while(!glfwWindowShouldClose(m_window)){
        glfwPollEvents();
        RunCuda();

        glBindBuffer(GL_PIXEL_UNPACK_BUFFER, m_pbo);
        glBindTexture(GL_TEXTURE_2D, m_image);
        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_width, m_height, GL_RGBA, 
                        GL_UNSIGNED_BYTE, NULL);
        glClear(GL_COLOR_BUFFER_BIT);   

        // VAO, shader program, and texture already bound
        glDrawElements(GL_TRIANGLES, 6,  GL_UNSIGNED_SHORT, 0);
        glfwSwapBuffers(m_window);
    }
    glfwDestroyWindow(m_window);
    glfwTerminate();
#endif
}
Ejemplo n.º 2
0
void Visual::Display()
{
    //sdkStartTimer(&_timer);

    // run CUDA kernel to generate vertex positions
    RunCuda(&_vboResource);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // set view matrix
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0.0, 0.0, _translateZ);
    glRotatef(_rotateX, 1.0, 0.0, 0.0);
    glRotatef(_rotateY, 0.0, 1.0, 0.0);

    // render from the _vbo
    glBindBuffer(GL_ARRAY_BUFFER, _vbo);
    glVertexPointer(4, GL_FLOAT, 0, 0);

    glEnableClientState(GL_VERTEX_ARRAY);
    glColor3f(1.0, 0.0, 0.0);
    glDrawArrays(GL_POINTS, 0, MeshWidth * MeshHeight);
    glDisableClientState(GL_VERTEX_ARRAY);

    glutSwapBuffers();

    _anim += 0.01f;

    //sdkStopTimer(&_timer);
    ComputeFPS();
}
Ejemplo n.º 3
0
void Visual::Main()
{
    // create VBO
    CreateVBO(&_vbo, &_vboResource, cudaGraphicsMapFlagsWriteDiscard);

    // run the cuda part
    RunCuda(&_vboResource);

    // start rendering mainloop
    glutMainLoop();
}