Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Try to using OpenGL  (Read 1214 times)

0 Members and 1 Guest are viewing this topic.

JoseMan

  • Newbie
  • *
  • Posts: 8
    • View Profile
Try to using OpenGL
« on: July 23, 2018, 07:39:09 pm »
Hi there :),

I want to draw OpenGL-stuff in a RenderTexture. It works fine, if I use the code from the OpenGL-Example and modify it a little bit to use glVertexPointer and glNormalPointer.
But I want to use a shader so I can't use glVertex- and glNormalPointer

But when I use to do this, nothing happens and the screen7renderTexture keeps black!
The code:
void Game::makeTestModel()
{
        glewInit();


        int vertexShader = glCreateShader(GL_VERTEX_SHADER);
        glShaderSource(vertexShader, 1, &vertexShaderSource, NULL);
        glCompileShader(vertexShader);
        // check for shader compile errors
        int success;
        char infoLog[512];
        glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
        if (!success)
        {
                glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
                //std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << std::endl;
        }
        // fragment shader
        int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
        glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL);
        glCompileShader(fragmentShader);
        // check for shader compile errors
        glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success);
        if (!success)
        {
                glGetShaderInfoLog(fragmentShader, 512, NULL, infoLog);
                //std::cout << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << infoLog << std::endl;
        }
        // link shaders
        shaderProgram = glCreateProgram();
        glAttachShader(shaderProgram, vertexShader);
        glAttachShader(shaderProgram, fragmentShader);
        glLinkProgram(shaderProgram);
        // check for linking errors
        glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
        if (!success) {
                glGetProgramInfoLog(shaderProgram, 512, NULL, infoLog);
                //std::cout << "ERROR::SHADER::PROGRAM::LINKING_FAILED\n" << infoLog << std::endl;
        }
        glDeleteShader(vertexShader);
        glDeleteShader(fragmentShader);


        float vertices[] = {
                0.5f, -0.5f, -10.0f,  // bottom right
                -0.5f, -0.5f, -10.0f,  // bottom left
                0.0f,  0.5f, -10.0f   // top
        };

        glGenVertexArrays(1, &VAO);
        glGenBuffers(1, &VBO);

        glBindVertexArray(VAO);

        glBindBuffer(GL_ARRAY_BUFFER, VBO);
        glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
        glEnableVertexAttribArray(0);
       
        glBindVertexArray(VAO);
}
 

And this is the drawing function:
void Game::internDraw()
{
        m_Context3DTexture.setActive(true);

        glBindVertexArray(VAO);

        glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);

        glUseProgram(shaderProgram);
        // render the triangle
        glDrawArrays(GL_TRIANGLES, 0, 3);

        m_Context3DTexture.setActive(false);
}

 

But all I see is a black screen/renderTexture. The shader is okay, I've tested the shader.
Did anybody know what I have to do to a scene (in a renderTexture) and use shader?

Chears :)
« Last Edit: July 23, 2018, 07:43:08 pm by JoseMan »

JoseMan

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Try to using OpenGL
« Reply #1 on: July 23, 2018, 08:22:46 pm »
Okay, sorry!!
The example doesn't still work, but I found out, that I can use shaders with the use of glVertexPointer, glNormalPointer and so on.

But If someone know why this code in my 1st post doesn't work, pleas tell me :)

 

anything