In this piece of code i managed to load a image with SDL and then succesfully pass it as a texture. Basically

image[0] = IMG_Load("../../tiles/1.png"); //path origin: framework/bin

if(image[0]!=nullptr) {
    //printf("h %d w %d d %d\n",image[0]->h, image[0]->w,d);
    std::cerr << "ERROR: image load failed: " << SDL_GetError() << "\n";

image[1] = IMG_Load("../../tiles/2.png"); //path origin: framework/bin

// set texture wrapping to GL_REPEAT (default wrapping method)
glTexParameteri(TexTarget, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(TexTarget, GL_TEXTURE_WRAP_T, GL_REPEAT);
// set texture filtering parameters
glTexParameteri(TexTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(TexTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

if(image[0]->format->BytesPerPixel == 4) {
    MM = GL_RGBA;

glTexImage2D(TexTarget, 0, MM, image[0]->w, image[0]->h, 0, MM, GL_UNSIGNED_BYTE, image[0]->pixels);

I would like to join both image[0] and image[1] in a new SDL_surface like image_total. I tried to use

    SDL_BlitSurface(image[0], NULL, image_total, NULL); 
   //somehow also load image[1] into image_total, for example below image[0]?
    glTexImage2D(TexTarget, 0, MM, image_total->w, image_total->h, 0, MM, GL_UNSIGNED_BYTE, image_total->pixels);

but It does not work (also, generates segm. fault). I can't find a proper example on how to use SDL_Blitsurface. How does it works?

If there is a way to join textures directly in openGL it will be also well accepted.

  • $\begingroup$ How do you want to "join" the textures? Side by side, one above the other, alpha-blending them on top of each other, adding the colours, ...? Do the dimensions match? $\endgroup$ – Dan Hulme Jan 21 at 17:31
  • $\begingroup$ @DanHulme as pointed out in code comment, I want to join the second below the first (or side by side, I assume the technique should be similar. Not blending or other types of composition). All images have 256x256 pixel $\endgroup$ – marcoresk Jan 23 at 10:22

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.