0

I am currently using SDL 1.2.4 and C++Builder 10.0 Seattle. I have set up a simple test program to check if everything is working correctly.

The following code compiles with no warning or errors, but gives me a runtime error:

Exception-Klasse $C0000005 mit Meldung 'access violation at 0x68cc46f5: read of address 0x00001701'. Prozess Project1.exe (2624)

int _tmain(int argc, _TCHAR* argv[]) {

    SDL_Init(SDL_INIT_VIDEO);
    SDL_SetVideoMode(640, 480, 32, SDL_OPENGL);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(70,(double)640/480,1,1000);

    while (true) {
        SDL_PumpEvents();
    }

    return 0;
}

If I remove glMatrixMode(...), the code "works", meaning a window pops up but displays nothing. So the MatrixMode seems to be the problem here.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Mohammed Li
  • 305
  • 3
  • 12
  • 1
    Could you check if call `SDL_SetVideoMode(640, 480, 32, SDL_OPENGL);` actually succeeded. See example here : https://www.libsdl.org/release/SDL-1.2.15/docs/html/sdlglsetattribute.html – vcp Mar 08 '16 at 08:55
  • 1
    Maybe SDL uses a modern OpenGL3 context with core profile. Deprecated functions, matrix included, are removed, so the function pointer of glMatrixMode is NULL (which explains the access violation). – Youka Mar 08 '16 at 09:00

1 Answers1

1

In case anyone finds this thread via google:

I downloaded opengl32.lib and gl32.lib for Borland compilers. Those files were broken apperently. Don't know the source anymore, but be cautious when using a file called bc_libs.zip

I created the .lib myself with the .dll found in windows/system32.

Mohammed Li
  • 305
  • 3
  • 12
  • `*.lib` can be link file for a `*.dll` or a static library (something liek `*.obj`). Borland uses for link files Intel format and Microsoft use its own (see OMF/COMF difference). So if you are using either wrong format of link file or if you use library as a dll link file or vice versa then you got problems. Borland has its own libs stored in `#include ` linking the correct things where it should (unless you change the include paths or BCB instalation files). Usually if you include it prior to any other lib (like SDL) it should override the wrong linkage from MS based libs. – Spektre Mar 08 '16 at 13:40
  • also some libs need to add a specific `#define` macro or include to set up for use inside Borland environments. See [Setting up OpenGL in Borland C++](http://stackoverflow.com/a/26177014/2521214) and [How to render an openGL frame in C++ builder?](http://stackoverflow.com/a/20679773/2521214) – Spektre Mar 08 '16 at 13:40