NO

Author Topic: SDL_opengl.h seems to be causing issues  (Read 7114 times)

siwenjo

  • Guest
SDL_opengl.h seems to be causing issues
« on: January 10, 2014, 01:54:12 AM »
The following code compiles and opens an SDL2 window so long as SDL_opengl.h is commented out. When included I get five errors:

...\Pellesc\Include\Win\basetsd.h(213): error #2120: Redeclaration of 'DWORD', previously declared at ...\Pellesc\Include\Win\windef.h(99); expected 'unsigned long int' but found 'unsigned long long int'.

...\Pellesc\Include\Win\winnt.h(244): error #2120: Redeclaration of 'LONG', previously declared at ...\Pellesc\Include\Win\basetsd.h(72); expected 'long long int' but found 'long int'.

...\Pellesc\Include\Win\winnt.h(1424): error #2179: '-1' is an invalid array size
...\Pellesc\Include\Win\winnt.h(1425): error #2179: '-1' is an invalid array size
...\Pellesc\Include\Win\winnt.h(1426): error #2179: '-1' is an invalid array size

The actual lines causing issues are:

basetsd.h(213): typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
windef.h(99):     typedef unsigned long DWORD;

and:

winnt.h(244):    typedef long LONG;
basetsd.h(72):  typedef __int64 LONG_PTR, *PLONG_PTR;

Code: [Select]
#define SDL_MAIN_HANDLED
typedef int bool;
#define true 1
#define false 0

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#include "SDL2/SDL.h"
#include "SDL2/SDL_opengl.h"

#pragma comment(lib, "SDL2.lib")

SDL_Window* win;
SDL_GLContext context;
bool running = true;

void setupSDL(void);

int main(int argc, char *argv[]){
#ifdef SDL_MAIN_HANDLED
SDL_SetMainReady();
#endif

setupSDL();

while(running){
SDL_Event e;
while(SDL_PollEvent(&e)){
switch(e.type){
case SDL_KEYDOWN:
if(e.key.keysym.sym == SDLK_ESCAPE) running = 0;
break;
default:
break;
}
}

SDL_GL_SwapWindow(win);
}

SDL_GL_DeleteContext(context);
SDL_DestroyWindow(win);
SDL_Quit();

return 0;
}

void setupSDL(void){
SDL_assert(SDL_Init(SDL_INIT_VIDEO) > -1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS | SDL_WINDOW_SHOWN;
win = SDL_CreateWindow("3Doodle", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1024, 768, flags);
SDL_assert(win != NULL);

context = SDL_GL_CreateContext(win);
SDL_assert(context != NULL);
}

I am using timovjl's SDL2 dll and lib with SDL2-devel-2.0.1-VC include files because these include the SDL_opengl.h header (I assume that the SDL2 dll does not export opengl functions and that the SDL_opengl.h interfaces with the graphic card's opengl32.dll).

I am compiling with a bat file:

Code: [Select]
del bin\App.exe
set libs=bin\main.o

cc /c -Tamd64-coff -Ze main.c -Fobin\main.o

cc -Wall %libs% /OUT:bin\App.exe

bin\App.exe

To make opengl work with PellesC I have also tried glew, building the lib with polib from the dll,  podumping the dll and making a def file and polibing that into a lib, and compiling glew.c directly into the executable (which works with mingw), but on PellesC it throws cdecl errors. There is no information to be had by googling and I am out of ideas.
« Last Edit: January 10, 2014, 02:34:21 AM by siwenjo »

JohnF

  • Guest
Re: SDL_opengl.h seems to be causing issues
« Reply #1 on: January 10, 2014, 11:45:52 AM »
I don't know if it applies to your code but I've seen errors like that when windows.h is not included.

John


Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: SDL_opengl.h seems to be causing issues
« Reply #2 on: January 10, 2014, 02:24:24 PM »
Maybe there are problems in SDL_config.h
These are not working in PellesC 64-bit (_MSC_VER = 1100)
Code: [Select]
/* Older Visual C++ headers don't have the Win64-compatible typedefs... */
#if ((_MSC_VER <= 1200) && (!defined(DWORD_PTR)))
#define DWORD_PTR DWORD
#endif
#if ((_MSC_VER <= 1200) && (!defined(LONG_PTR)))
#define LONG_PTR LONG
#endif
so windows.h must be before that file or define _MSC_VER=1300

SDL2-devel-2.0.1-VC.zip is good choice for PellesC
« Last Edit: January 10, 2014, 05:56:35 PM by timovjl »
May the source be with you

siwenjo

  • Guest
Re: SDL_opengl.h seems to be causing issues
« Reply #3 on: January 10, 2014, 09:02:47 PM »
Thank you. Adding <windows.h> fixed the problem. I also replaced the SDL2 includes, libs and dll with the SDL2-devel-2.0.1-VC (straight out of the box) and they are working.


SOLVED: see below if interested.

I added to the project above the following function calling glGetString and glGetError (both should be in the Windows provided opengl32.

Code: [Select]
void checkError(void){
puts("CALLED");
const char* renderer = (const char*) glGetString(GL_RENDERER);
puts(renderer);
const char* version = (const char*) glGetString(GL_VERSION);
puts(version);
const char* glslVersion = (const char*) glGetString(GL_SHADING_LANGUAGE_VERSION);
puts(glslVersion);

GLenum error = glGetError();
switch(error){
case GL_NO_ERROR: puts("no error"); break;
case GL_INVALID_ENUM: puts("invalid enum"); break;
case GL_INVALID_VALUE: puts("invalid value"); break;
case GL_OUT_OF_MEMORY: puts("out of memory"); break;
case GL_INVALID_FRAMEBUFFER_OPERATION: puts("invalid framebuffer operation"); break;
default: break;
}
}

And I get the errors:

POLINK: error: Unresolved external symbol '__imp_glGetString'.
POLINK: error: Unresolved external symbol '__imp_glGetError'.

My bat file for compilation is:

Code: [Select]
del bin\App.exe
set files=bin\main.o

cc /c -Tamd64-coff -Ze main.c -Fobin\main.o

cc -Wall %files% /OUT:bin\App.exe

bin\App.exe

I know mingw wants you to add -lSDL2main -lSDL -lopengl32 -lwindows the the compile line, and the PellesC IDE has a library and object files section in the linker tab and I suspect i need this in the bat file. I have tried appending opengl32.lib using both the /LIBPATH and the /INCLUDE options but the compiler complains that opengl32.lib is an unknown symbol.

I am assuming in all this that the SDL_opengl.h header is a replacement for Glew and does itself provide the symbol table into the opengl32.dll. GLView tells me my opengl version is 4.1.


SOLVED: add

Code: [Select]
#pragma comment(lib, "opengl32.lib")
along with the pragma to add in the SDL2
« Last Edit: January 10, 2014, 10:18:15 PM by siwenjo »