Running testshader.c

I’m new in openGL. There is a macro #ifdef HAVE_OPENGL in the test\testshader.c file. Where this macro shoud be defined? How can I run this test on Windows?

The HAVE_* macros usually get defined by the build system, but Windows never really enjoyed having such a solution that was used by everyone. SDL provides some preconfigured headers and Visual Studio projects there.

The testshader.c test doesn’t have a project yet, but the project for testgl2.c could be used as a template for it. This is where HAVE_OPENGL gets defined for the tests.

If you don’t use Visual Studio, just define it yourself when you compile it.

Thank you! I use Visual Studio. I will try build this project.

And as far as described Remarks for SDL_GL_CreateContext on windows I need SDL_GL_GetProcAddress to invoke GL-functions. It seem to be this solution works for all supported platforms.
Or use wrappers like glew, glfw.

Am I right or wrong?

Yes, that is correct.

The OpenGL specification doesn’t specify how to get the procedures of the API so each implementation has their own thing to handle that (GLX, WGL, CGL, …). Luckily, they all kind of work the same. The only thing you have to be aware of is that you only should expect valid function pointers for procedures that the context supports. That means checking the OpenGL version and extensions of the context is required.

You’ll quickly need a lot of OpenGL functions and writing the checking and loading is very time consuming. It’s indeed recommended to use one of those wrappers.

ChliHug, according your reply I did find testgles2.vcxproj which uses testgles2.c source code. I running them and it draws rotating cude.
This file has useful marco SDL_PROC with 2 definitions
the first:

typedef struct GLES2_Context
{
#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
#include "../src/render/opengles2/SDL_gles2funcs.h"
#undef SDL_PROC
} GLES2_Context;

and second

#if defined __SDL_NOGETPROCADDR__
#define SDL_PROC(ret,func,params) data->func=func;
#else
#define SDL_PROC(ret,func,params) \
    do { \
        data->func = SDL_GL_GetProcAddress(#func); \
        if ( ! data->func ) { \
            return SDL_SetError("Couldn't load GLES2 function %s: %s", #func, SDL_GetError()); \
        } \
    } while ( 0 );
#endif /* __SDL_NOGETPROCADDR__ */

and include gles function list in the …/src/render/opengles2/SDL_gles2funcs.h. There some of them below

SDL_PROC(void, glActiveTexture, (GLenum))
SDL_PROC(void, glAttachShader, (GLuint, GLuint))
SDL_PROC(void, glBindAttribLocation, (GLuint, GLuint, const char *))
SDL_PROC(void, glBindTexture, (GLenum, GLuint))
SDL_PROC(void, glBlendEquationSeparate, (GLenum, GLenum))

I tried build my test sample project and it successfully loads this functions on my windows and Android 4.x

openglesdriver.h

Your reply was very helpful and now I know how to exec opengles functions.

Since you specifically mention Android, be aware that this platform apparently returns non-NULL pointers on failure. If you just need OpenGL ES 2 functions it should be fine, but this macro will be insufficient for extensions.

I want do apps for Android and iOS. When i tried to get pointer to glOrtho which not in GLES, android returned null pointer.