Example #1
0
    void RenderGeometry(Rocket::Core::Vertex* verticies, int numVerticies, int* indices, int numIndicies, Rocket::Core::TextureHandle texture, const Rocket::Core::Vector2f& translation) {
        polyVert_t* verts = createVertexArray(verticies, numVerticies);

        re.Add2dPolysIndexed(verts, numVerticies, indices, numIndicies, translation.x, translation.y, texture ? (qhandle_t) texture : whiteShader);

        Z_Free(verts);
    }
Example #2
0
    RocketCompiledGeometry(Rocket::Core::Vertex* verticies, int numVerticies, int* _indices, int _numIndicies, qhandle_t shader)
            : numVerts(numVerticies), numIndicies(_numIndicies) {
        this->verts = createVertexArray(verticies, numVerticies);

        this->indices = (int*) Z_Malloc(sizeof(int) * _numIndicies);
        Com_Memcpy(indices, _indices, _numIndicies * sizeof(int));

        this->shader = shader;
    }
void MainWindow::on_pushButton_3_clicked()
{
    QMessageBox* box = new QMessageBox;
    if(ui->textEdit->toPlainText().size() == 0)
    {
        box->setText("Enter something you wanna to encode");
        box->show();
    }
    else{
        createVertexArray();

        float summ = 0;
        for(int i = 0; i < arrayOfVertexes.size(); i++)
            {
                summ += arrayOfVertexes.at(i).getValue();
            }

        if(round(summ*10)/10 != 1.0)
            {
                box->setText("Summ of numbers need to be 1, in your case it is " + QString::number(summ));
                box->show();
            }
        else if(arrayOfVertexes.size() == 1)
            {
                box->setText("You need at least 2 elements!");
                box->show();
            }
        else
            {
                ui->horizontalSlider->setMinimum(1);
                ui->horizontalSlider->setMaximum(10);
                ui->horizontalSlider->setValue(1);
                ui->label_2->setText(QString::number(ui->horizontalSlider->minimum()));
                ui->label_4->setText(QString::number(ui->horizontalSlider->maximum()));
                ui->label_6->setText(QString::number(ui->horizontalSlider->value()));

                ui->horizontalSlider->setEnabled(true);
                ui->pushButton_2->setEnabled(true);
        }
    }
    on_pushButton_2_clicked();
}
Example #4
0
void createFaces(osg::Geometry& geometry, Polyhedron const& polyhedron, unsigned int faceMask = PolyhedronGeometry::All)
{
    osgUtil::Tessellator tessellator;
    tessellator.setTessellationType(osgUtil::Tessellator::TESS_TYPE_POLYGONS);
    tessellator.setWindingType(osgUtil::Tessellator::TESS_WINDING_NONZERO);

    auto _vertices = getOrCreateVertexArray(geometry);
    auto _normals = getOrCreateNormalArray(geometry);
    auto _colors = getOrCreateColorArray(geometry);

    osg::ref_ptr<osg::Vec3Array> vertices = createVertexArray(polyhedron);
    VertexIndexArrays polygons = createVertexIndexArrays(polyhedron);

    for (auto const& polygon: polygons)
    {
        assert(polygon && polygon->size() >= 3);

        if (!(faceMask & PolyhedronGeometry::FaceMaskFromSides(polygon->size()))) continue;

        auto first = _vertices->size();
        auto count = polygon->size();

        auto normal = detail::calculateNormal(vertices, polygon);
        auto color = detail::calculateColor(vertices, polygon);

        for (auto i = 0u; i < polygon->size(); ++i)
        {
            auto vertex = vertices->at(polygon->at(i));
            _vertices->push_back(vertex);
            _normals->push_back(normal);
            _colors->push_back(color);
        }

        geometry.addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON, first, count));
    }

    tessellator.retessellatePolygons(geometry);
}
	void SpriteBatcher::init() {
		//Set up the VAO and VBO
		createVertexArray();
	}
Example #6
0
	void SpriteBatch::init()
	{
		createVertexArray();
	}
Example #7
0
 SpriteBatch::SpriteBatch()
 {
     createVertexArray();
 }
void MainWindow::on_pushButton_2_clicked()
{
    createVertexArray();
    std::vector<Vertex> vertexes;
    std::vector<Vertex> tempArray1, tempArray2;

    Vertex temp;

    int rounds = ui->horizontalSlider->value();

    bool currentArray = false;
    tempArray1 = arrayOfVertexes;

    for(int i = 1; i < rounds; i++)
    {
        if(!currentArray)
            tempArray2.clear();
        else
            tempArray1.clear();

        for(int j = 0; j < arrayOfVertexes.size(); j++)
        {
            if(!currentArray)
            {
                for(int n = 0; n < tempArray1.size(); n++)
                {
                    temp.setName(tempArray1.at(n).getName() + arrayOfVertexes.at(j).getName());
                    temp.setRoot();
                    temp.setValue(tempArray1.at(n).getValue() * arrayOfVertexes.at(j).getValue());
                    tempArray2.push_back(temp);
                }
            }
            else
            {
                for(int n = 0; n < tempArray2.size(); n++)
                {
                    temp.setName(tempArray2.at(n).getName() + arrayOfVertexes.at(j).getName());
                    temp.setRoot();
                    temp.setValue(tempArray2.at(n).getValue() * arrayOfVertexes.at(j).getValue());
                    tempArray1.push_back(temp);
                }
            }
        }
        currentArray = !currentArray;
    }

    if(currentArray)
        vertexes = tempArray2;
    else vertexes = tempArray1;


    Calculator* calculator = new Calculator(vertexes, ui->centralWidget);
    if(!calculateEntropy)
    {
        ui->Entropy->setText(QString::number(calculator->entropy()));
        entropy = calculator->entropy();
        calculateEntropy = true;
    }

//    connect(&watcher, SIGNAL(finished()), this, SLOT(encodingEnd()));
//    connect(&watcher, SIGNAL(progressValueChanged(int)), this, SLOT(progressChanged(int)));
//    QFuture<std::vector<Vertex>> future = QtConcurrent::run(calculator, &Calculator::codding);
//    watcher.setFuture(future);
    arrayOfVertexes = calculator->codding();
    encodingEnd();
}
Example #9
0
// entry point
int main(int argc, char *argv[])  
{
    //------------------------------------------
    // create a vertex array based on facet data
    //------------------------------------------

    // vertices on the perimeter

    const int N1 = 100;  // base circle
    const int N2 = 100;  // rolling circle
///   const int N3 = 4;  // marker circle

    float* verticesBaseCircle    = new float[(N1+2)*10];  // baseline circle
    float* verticesRollingCircle = new float[(N2+2)*10];  // rolling circle
//    float* verticesMarkerCircle  = new float[(N3+2)*10];  // marker circle

    createVertexArray(N1, R,    verticesBaseCircle,    true);
    createVertexArray(N2, r,    verticesRollingCircle, true);
//    createVertexArray(N3, r/20, verticesMarkerCircle,  false);

    //--------------------------------
    //   Create a WINDOW using GLFW
    //--------------------------------
    GLFWwindow *window;

    // initialize the library
    if(!glfwInit())
    {
        return -1;
    }

    // window size for displaying graphics
    int WIDTH  = 600;
    int HEIGHT = 600;

    // set screen coordinates for display based on aspect ratio
    float x_min = - R - 2*fabs(r) - fabs(r);
    float x_max =   R + 2*fabs(r) + fabs(r);
    float y_min = (float) HEIGHT * x_min / (float) WIDTH;
    float y_max = (float) HEIGHT * x_max / (float) WIDTH;

    // set the window's display mode
    window = glfwCreateWindow(WIDTH, HEIGHT, "Rolling Circle", NULL, NULL);
    if(!window)
    {
        glfwTerminate();
	    return -1;
    }

    // make the windows context current
    glfwMakeContextCurrent(window);

    // register the keyboard input callback function defined at the top
    glfwSetKeyCallback(window, key_callback);

//  // create a Vertex Buffer Object (VBO) and bind the vertex array to it
//  // makes rendering faster because data is copied to GPU memory
//  GLuint bufferID;
//  glGenBuffers(1, &bufferID);
//  glBindBuffer(GL_ARRAY_BUFFER, bufferID);
//  glBufferData(GL_ARRAY_BUFFER,(N+2)*10*sizeof(GLfloat),verticesRollingCircle,GL_STATIC_DRAW);

    // initialize animation parameters 
    int frame = 0;

    float roll_distance = 0.0, d_roll_distance = 0.0075; 

    float PI = 3.1415926;

    bool clearWindow = true;

    while(running)
    {
        // calculate new position of the rolling ball
        if(!pause) roll_distance += d_roll_distance;
      
        // calculate total angle by which the rolling circle should rotate
        float theta = roll_distance*(1.0/r + 1.0/R);
        float theta_new = (roll_distance + d_roll_distance)*(1.0/r + 1.0/R);

        // detect and print number of complete rotations
        float numRotations = theta * 180.0 / (PI*360);
        float numRotations_new = theta_new * 180.0 / (PI*360);
        int L1 = (int)numRotations;
        int L2 = (int)numRotations_new;
        if(L1 != L2) std::cout << "Number of rotations = " << L2 << std::endl;

        // center coordinates of the rolling circle
        float move_x = (R + r)*cos(roll_distance/R);
        float move_y = (R + r)*sin(roll_distance/R);

        // render the fixed circle
        drawCircle(window, clearWindow, x_min, x_max, y_min, y_max,
                     verticesBaseCircle, (N1+2),
                     0.0, 0.0, 0.0, true);

        // swap front and back buffers
        glfwSwapBuffers(window);

        // render the rolling circle
        drawCircle(window, clearWindow, x_min, x_max, y_min, y_max,
                     verticesRollingCircle, (N2+2),
                     move_x, move_y, theta, true);

        // swap front and back buffers
        glfwSwapBuffers(window);
/*
        // render the marker circle

        float pencil = r;

        drawCircle(window, clearWindow, x_min, x_max, y_min, y_max,
                     verticesMarkerCircle, (N3+2),
                     move_x + pencil * cos(theta), move_y + pencil * sin(theta), theta, false);

        // swap front and back buffers
        glfwSwapBuffers(window);
*/
        // poll for and processs events
        glfwPollEvents();

//      if (clearWindow == true) clearWindow = false;
    }

    // free memory
    delete[] verticesBaseCircle;
    delete[] verticesRollingCircle;
//  delete[] verticesMarkerCircle;

    glfwDestroyWindow(window);
    glfwTerminate();

    return 0;    // main program is successful
}
Example #10
0
GraphicsContext3D::GraphicsContext3D(GraphicsContext3DAttributes attributes, HostWindow*, GraphicsContext3D::RenderStyle renderStyle)
    : m_currentWidth(0)
    , m_currentHeight(0)
    , m_attrs(attributes)
    , m_texture(0)
    , m_compositorTexture(0)
    , m_fbo(0)
#if USE(COORDINATED_GRAPHICS_THREADED)
    , m_intermediateTexture(0)
#endif
    , m_depthStencilBuffer(0)
    , m_layerComposited(false)
    , m_multisampleFBO(0)
    , m_multisampleDepthStencilBuffer(0)
    , m_multisampleColorBuffer(0)
    , m_private(std::make_unique<GraphicsContext3DPrivate>(this, renderStyle))
{
    makeContextCurrent();

    validateAttributes();

    if (renderStyle == RenderOffscreen) {
        // Create a texture to render into.
        ::glGenTextures(1, &m_texture);
        ::glBindTexture(GL_TEXTURE_2D, m_texture);
        ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        ::glBindTexture(GL_TEXTURE_2D, 0);

        // Create an FBO.
        ::glGenFramebuffers(1, &m_fbo);
        ::glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);

#if USE(COORDINATED_GRAPHICS_THREADED)
        ::glGenTextures(1, &m_compositorTexture);
        ::glBindTexture(GL_TEXTURE_2D, m_compositorTexture);
        ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

        ::glGenTextures(1, &m_intermediateTexture);
        ::glBindTexture(GL_TEXTURE_2D, m_intermediateTexture);
        ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

        ::glBindTexture(GL_TEXTURE_2D, 0);
#endif

        m_state.boundFBO = m_fbo;
        if (!m_attrs.antialias && (m_attrs.stencil || m_attrs.depth))
            ::glGenRenderbuffers(1, &m_depthStencilBuffer);

        // Create a multisample FBO.
        if (m_attrs.antialias) {
            ::glGenFramebuffers(1, &m_multisampleFBO);
            ::glBindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO);
            m_state.boundFBO = m_multisampleFBO;
            ::glGenRenderbuffers(1, &m_multisampleColorBuffer);
            if (m_attrs.stencil || m_attrs.depth)
                ::glGenRenderbuffers(1, &m_multisampleDepthStencilBuffer);
        }
    }

#if !USE(OPENGL_ES_2)
    ::glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);

    if (GLContext::current()->version() >= 320) {
        // From version 3.2 on we use the OpenGL Core profile, so request that ouput to the shader compiler.
        // OpenGL version 3.2 uses GLSL version 1.50.
        m_compiler = ANGLEWebKitBridge(SH_GLSL_150_CORE_OUTPUT);

        // From version 3.2 on we use the OpenGL Core profile, and we need a VAO for rendering.
        // A VAO could be created and bound by each component using GL rendering (TextureMapper, WebGL, etc). This is
        // a simpler solution: the first GraphicsContext3D created on a GLContext will create and bind a VAO for that context.
        GC3Dint currentVAO = 0;
        getIntegerv(GraphicsContext3D::VERTEX_ARRAY_BINDING, &currentVAO);
        if (!currentVAO) {
            m_vao = createVertexArray();
            bindVertexArray(m_vao);
        }
    } else {
        // For lower versions request the compatibility output to the shader compiler.
        m_compiler = ANGLEWebKitBridge(SH_GLSL_COMPATIBILITY_OUTPUT);

        // GL_POINT_SPRITE is needed in lower versions.
        ::glEnable(GL_POINT_SPRITE);
    }
#else
    m_compiler = ANGLEWebKitBridge(SH_ESSL_OUTPUT);
#endif

    // ANGLE initialization.
    ShBuiltInResources ANGLEResources;
    ShInitBuiltInResources(&ANGLEResources);

    getIntegerv(GraphicsContext3D::MAX_VERTEX_ATTRIBS, &ANGLEResources.MaxVertexAttribs);
    getIntegerv(GraphicsContext3D::MAX_VERTEX_UNIFORM_VECTORS, &ANGLEResources.MaxVertexUniformVectors);
    getIntegerv(GraphicsContext3D::MAX_VARYING_VECTORS, &ANGLEResources.MaxVaryingVectors);
    getIntegerv(GraphicsContext3D::MAX_VERTEX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxVertexTextureImageUnits);
    getIntegerv(GraphicsContext3D::MAX_COMBINED_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxCombinedTextureImageUnits);
    getIntegerv(GraphicsContext3D::MAX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxTextureImageUnits);
    getIntegerv(GraphicsContext3D::MAX_FRAGMENT_UNIFORM_VECTORS, &ANGLEResources.MaxFragmentUniformVectors);

    // Always set to 1 for OpenGL ES.
    ANGLEResources.MaxDrawBuffers = 1;

    GC3Dint range[2], precision;
    getShaderPrecisionFormat(GraphicsContext3D::FRAGMENT_SHADER, GraphicsContext3D::HIGH_FLOAT, range, &precision);
    ANGLEResources.FragmentPrecisionHigh = (range[0] || range[1] || precision);

    m_compiler.setResources(ANGLEResources);

    ::glClearColor(0, 0, 0, 0);
}