2

I am using this answer to embed my image in the .exe:

Embedding resources in executable using GCC

Here are the relevant bits of my code:

GLuint grass_DTexture;

extern char binary_grass_D_bmp_start[];
extern char binary_grass_D_bmp_size[];

short loadTexture(char *imageData[], GLuint *texture) {
    *texture = SOIL_load_OGL_texture_from_memory(imageData, sizeof(*imageData), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

    return 1;
}

loadTexture(&binary_grass_D_bmp_start, &grass_DTexture);

However the texture does not load and I just get a whitish grey surface.

EDIT: I know this was not my original question, however I am having difficulty using mipmaps. I modified my loadTexture function to this: short loadTexture(char *imageData[], GLuint *texture, int width, int height) { glEnable(GL_TEXTURE_2D); glGenTextures(1, texture); glBindTexture(GL_TEXTURE_2D, *texture);

    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

    *texture = SOIL_load_OGL_texture_from_memory(imageData, sizeof(*imageData), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_MIPMAPS);

    //gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, imageData);

    //glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, width, height);
    //glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, imageData);
    //glGenerateMipmap(GL_TEXTURE_2D);

    glDisable(GL_TEXTURE_2D);
    return 1;
}

This time, the exe crashes as soon as it is run. I am also greeted with the following warning, which could be the cause of this (probably missing an * or an & somewhere):

init.c:76:2: warning: passing argument 1 of 'loadTexture' from incompatible poin
ter type [enabled by default]
loadTexture.h:1:7: note: expected 'char **' but argument is of type 'char (*)[]'

I have managed to narrow the crash to the SOIL_load_OGL_texture_from_memory call.

Community
  • 1
  • 1
CHRIS
  • 957
  • 3
  • 10
  • 27

1 Answers1

2

GL_TEXTURE_MIN_FILTER defaults to GL_NEAREST_MIPMAP_LINEAR​.

Upload some mipmaps or switch to GL_NEAREST or GL_LINEAR.

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • Thanks for your answer, it really steered me in the right direction. But when I try and use mipmaps, I receive a new problem. I'm new to OpenGL, and a lot of tutorials I have come across use either an outdated library like GLAUX or just use file access, and do not embed the textures. – CHRIS Jul 16 '13 at 20:09
  • @CHRIS: Why the `gluBuild2DMipmaps()`? What was wrong with `SOIL_FLAG_MIPMAPS`? – genpfault Jul 16 '13 at 20:19
  • Ah, I think I may have come across my issue. My imageData is the contents of a BMP file. Is the function SOIL_load_OGL_texture_from_memory designed to be used with raw pixel data? – CHRIS Jul 16 '13 at 20:23
  • I think it expects the contents of a supported image file, not raw pixels. – genpfault Jul 16 '13 at 20:28
  • Hmm, well. I'm stumped then. – CHRIS Jul 16 '13 at 21:32
  • Note that simply loading the texture from an external file using only this one line works: *texture = SOIL_load_OGL_texture("image.bmp", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y); so it's not a problem with lighting or anything else specific to my project. – CHRIS Jul 16 '13 at 21:34