Hi,
I’m currently working on a C project that until recently had been coded completely against the AmigaOS 3 API. However, I have decided to try and create a separate strand within the project that’ll output to SDL/OpenGL.
The SDL part of the project has been arranged so that the GL initiation code is in a file main_sdl.c, and the actual graphical functions are within another code file, graphics.c. In main_sdl.c I currently have
Code:
/* SDL errors yield nonzero values */
if (!SDL_Init(SDL_INIT_VIDEO)) {
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
if((coret.gfx->screen = SDL_SetVideoMode(SCR_W, SCR_H, 32,
SDL_OPENGL))) {
init_gfx_buffer(&coret);
SDL_WM_SetCaption("SoR", "SoR");
glClearColor(0, 0, 0, 0);
glEnable(GL_TEXTURE_2D);
glViewport(0, 0, SCR_W, SCR_H);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,SCR_W, SCR_H, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
Following this code is some code I pasted over from one of the functions in graphics.c, most of which is copied below:
Code:
SDL_Surface *surface;
if((surface = IMG_Load((char*)filename))) {
GLuint texture;
glGenTextures(1, &texture);
glBindTexture( GL_TEXTURE_2D, texture );
SDL_LockSurface(surface);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, surface->w, surface->h, 0,
GL_RGB, GL_UNSIGNED_BYTE, surface->pixels);
UWORD w = surface->w;
UWORD h = surface->h;
SDL_UnlockSurface(surface);
SDL_FreeSurface(surface);
/* Sets filters for texture (smaller, larger) */
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, texture);
glBegin( GL_QUADS );
glTexCoord2i(0, 0);
glVertex2f(0, 0);
glTexCoord2i(1, 0);
glVertex2f(w - 1, 0);
glTexCoord2i(1, 1);
glVertex2f(w - 1, h - 1);
glTexCoord2i(0, 1);
glVertex2f(0, h - 1);
glEnd();
SDL_GL_SwapBuffers();
SDL_Delay(3000);
glDeleteTextures(1, &texture);
} else {
fprintf(stderr, “Image file oops: %s\n”, SDL_GetError());
}
When I run the project, the copy of the code in the initialising function works and displays the image, however the copy in graphics.c, which is run after the initialising code and from a different function in main_sdl.h, instead draws a black box in place of the texture. Where could I going wrong?
Thanks, Matt