• Re: C++ invalid conversion

    From Ben Bacarisse@21:1/5 to montillaramirezh@gmail.com on Wed Oct 27 02:51:36 2021
    Heitber Andrés Montilla Ramirez <montillaramirezh@gmail.com> writes:

    Hi everyone I want to know why this error apperars to my code, I'm
    trying to do an OpenGL App Using codeblocks, I re-checked the code
    twice with the original tutorial and everything is ok. now the
    compiler throws the following error:

    |error: invalid conversion from 'const void*' to 'HANDLE {aka void*}' |[-fpermissive]|

    I want your help to solve this issue.

    Well, you can get round the problem by using const_cast:

    HANDLE h = const_cast<HANDLE>(...);

    but it might well pay to find out why the conversion from a pointer to
    const to a pointer to non-const is happening. It is potentially unsafe,
    so finding out what's really going on is a good idea.

    And it's possible that everything should simply be a HANDLE, and the
    mistake is to have any const void * pointers at all.

    If you tell people where the error occurs, you might get more help on
    the details. (I don't have all the right headers installed, so I can't
    use a compiler to tell me where the problem is.)

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Heitber_Andr=C3=A9s_Monti@21:1/5 to All on Tue Oct 26 18:24:26 2021
    Hi everyone I want to know why this error apperars to my code, I'm trying to do an OpenGL App Using codeblocks, I re-checked the code twice with the original tutorial and everything is ok.
    now the compiler throws the following error:

    |error: invalid conversion from 'const void*' to 'HANDLE {aka void*}' [-fpermissive]|

    I want your help to solve this issue.



    #define GLUT_DISABLE_ATEXIT_HACK
    #define GLEW_STATIC

    #if defined(_WIN32) || defined(_WIN64)
    #include <windows.h>
    #endif

    #include <thread>
    #include <string>
    #include <stdio.h>
    #include <GL/glew.h>
    #ifdef __APPLE__
    #include <GLUT/glut.h>
    #else
    #define GLUT_DISABLE_ATEXIT_HACK
    #include <GL/glut.h>
    #include <GL/gl.h>

    #endif
    #include "math_3d.h"


    GLuint VBO;


    static void RenderSceneCB()
    {
    glClear(GL_COLOR_BUFFER_BIT);

    glBindBuffer(GL_ARRAY_BUFFER, VBO);

    glEnableVertexAttribArray(0);

    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);

    glDrawArrays(GL_TRIANGLES, 0, 3);

    glDisableVertexAttribArray(0);

    glutSwapBuffers();
    }

    static void CreateVertexBuffer()
    {
    Vector3f Vertices[3];
    Vertices[0] = Vector3f(-1.0f, -1.0f, 0.0f);
    Vertices[1] = Vector3f(1.0f, -1.0f, 0.0f);
    Vertices[2] = Vector3f(0.0f, 1.0f, 0.0f);

    glGenBuffers(1, &VBO);
    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW); }

    static void AddShader(GLuint ShaderProgram, const char* pShaderText, GLenum ShaderType)
    {
    GLuint ShaderObj = glCreateShader(ShaderType);

    if(ShaderObj == 0){
    fprintf(stderr, "Error Creating shader type %d\n", ShaderType);
    exit(0);
    }

    const GLchar* p[1];
    p[0] = pShaderText;

    GLint Lengths[1];
    Lengths[0] = (GLint)strlen(pShaderText);

    glShaderSource(ShaderObj, 1, p, Lengths);

    glCompileShader(ShaderObj);

    GLint success;
    glGetShaderiv(ShaderObj, GL_COMPILE_STATUS, &success);

    if(!success){
    GLchar InfoLog[1024];
    glGetShaderInfoLog(ShaderObj, 1024, NULL, InfoLog);
    fprintf(stderr, "Error compiling shader type %d: '%s'\n", ShaderType, InfoLog);
    exit(1);
    }

    glAttachShader(ShaderProgram, ShaderObj);
    }


    const char* pVSFileName = "shader.vs";
    const char* pFSFileName = "shader.fs";

    static void CompileShaders()
    {
    GLuint ShaderProgram = glCreateProgram();

    if(ShaderProgram == 0){
    fprintf(stderr, "Error creating shader Program\n");
    exit(1);
    }

    std::string vs, fs;

    if (!ReadFile(pVSFileName, vs)){
    exit(1);
    };

    AddShader(ShaderProgram, vs.c_str(), GL_VERTEX_SHADER);

    if(!ReadFile(pFSFileName, fs)){
    exit(1);
    };

    AddShader(ShaderProgram, fs.c_str(), GL_FRAGMENT_SHADER);

    GLint Success = 0;
    GLchar ErrorLog[1024] = { 0 };

    glLinkProgram(ShaderProgram);

    glGetProgramiv(ShaderProgram, GL_LINK_STATUS, &Success);
    if(Success == 0){
    glGetProgramInfoLog(ShaderProgram, sizeof(ErrorLog), NULL, ErrorLog);
    fprintf(stderr, "Error linking shader program: '%s'\n", ErrorLog);
    exit(1);
    }

    glValidateProgram(ShaderProgram);
    glGetProgramiv(ShaderProgram, GL_VALIDATE_STATUS, &Success);
    if(!Success){
    glGetProgramInfoLog(ShaderProgram, sizeof(ErrorLog), NULL, ErrorLog);
    fprintf(stderr, "Invalid shader program: '%s'\n", ErrorLog);
    exit(1);
    }

    glUseProgram(ShaderProgram);

    }

    int main(int argc, char** argv)
    {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
    int width = 920;
    int height = 800;
    glutInitWindowSize(width, height);

    int x = 200;
    int y = 100;
    glutInitWindowPosition(x, y);
    int win = glutCreateWindow("Tutorial 03");
    printf("window id: %d\n", win);

    GLenum res = glewInit();
    if (res != GLEW_OK){
    fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
    return 1;
    }

    GLclampf Red = 0.0f, Green = 0.0f, Blue = 0.0f, Alpha = 0.0f;
    glClearColor(Red, Green, Blue, Alpha);

    CreateVertexBuffer();

    glutDisplayFunc(RenderSceneCB);

    glutMainLoop();

    return 0;

    }

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)