C++ Freeglut Run-Time Check Failure #2 - S, Visual Studio C++

-1

C++ I developing game engine but my code not working. I tried: Change position of code... Changing type

Here my code:

...
    #include "pch.h"
    #include <iostream>
    #include "glut.h"

    #include "conio.h"
    using namespace std;

    #include<stdio.h>
    #include "map_loader.h"
    #include "models.h"
    #include "IEDX_POLYTEX.h"
    #include "FONTGER/include/fontmann.h"
    #define KEY_ESC 27 /* GLUT doesn't supply this */
    #pragma comment(lib, "GLAUX_iedx_fonts.lib")

//Void display: i dont give full code. only this part of void Display()
...
    GLuint my_texture[13] = { 0xffaec900, 0x0000ffae, 0xc9ffaec9,
        0xffaec9ff, 0xaec90000, 0x00ffaec9,
        0x000000ff, 0xaec9ffae, 0xc9000000,
        0xffaec900, 0x00000000, 0x00ffaec9 }
        ;
    glTexImage2D(GL_TEXTURE_2D, 0, 3, 16, 16, 0,
        GL_RGB8, GL_UNSIGNED_BYTE, my_texture);
    glGenTextures(34, my_texture);
    glBindTexture(GL_TEXTURE_2D, 34);
...

when i run the my app for skiRun-Time Check Failure #2 - S, Visual Studio C++

no compiler errors etc.

no problem with linkers.

when app crashes and i try to click retry game.exe has stopped working...

c++
freeglut
asked on Stack Overflow Oct 1, 2019 by TRGamer TR • edited Oct 1, 2019 by TRGamer TR

1 Answer

0

It looks like you need to read an introduction to OpenGL; that code makes very little sense.

I believe the particular cause for the runtime error is that you're generating 34 texture names into an array that can only fit 13.
(Read the documentation carefully. If you don't understand, don't guess but keep studying.)

Remember that OpenGL is stateful and you must do some things in a certain order.

The normal way of doing things is

//Generate a texture name:
GLuint name = 0;
glGenTextures(1, &name);
// Bind this texture:
glBindTexture(GL_TEXTURE_2D, name);
// Now you can load the texture into OpenGL:
glTexImage2D(GL_TEXTURE_2D, 0, 3, 16, 16, 0,
             GL_RGB8, GL_UNSIGNED_BYTE, my_texture);

Your arguments to glTexImage2D also look questionable – they don't seem to match your texture array at all.

answered on Stack Overflow Oct 1, 2019 by molbdnilo

User contributions licensed under CC BY-SA 3.0