Texture from another texture

Started by
7 comments, last by MARS_999 16 years ago
Hi! All, So, I need some like this.... Suppose I have a image 500x500 and which is already loaded as texture. Now, I want to sliced the texture verticially (middle), so that I got two textures of 250x500 and 250x500. Anyone here to help? Thanks in advance.
Advertisement
Have you looked at glTexSubImage2D. I'm not sure if thats what you want but thats the first thing I would look at.
Quote:Original post by moo_gamer
Suppose I have a image 500x500 and which is already loaded as texture. Now, I want to sliced the texture verticially (middle), so that I got two textures of 250x500 and 250x500. Anyone here to help? Thanks in advance.

The best way would typically be not to split it at all, and instead set the texture coordinates for each object to use only the requisite half of the texture.

If you need texture wrapping for both halves this may not be feasible, in which case glTexSubImage2D is your friend.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

I'm having the same issue.

I tried the function you mentioned, but the texture is white now:

corona::Image *image = NULL;        for (int i = 0; i < size; i++)        {            image = corona::OpenImage(filenames, corona::PF_R8G8B8A8);            if (image)            {                glGenTextures(1, &textures.texture);                textures.w = image->getWidth();                textures.h = image->getHeight();                ids = textures.texture;                glBindTexture(GL_TEXTURE_2D, textures.texture);                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);                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);                if (image->getWidth() == 1000)                {                    glTexSubImage2D(GL_TEXTURE_2D, 0, 400, 400, image->getWidth() - 800, image->getHeight() - 800, GL_RGBA, GL_UNSIGNED_BYTE, image->getPixels());                }                else                {                    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->getWidth(), image->getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, image->getPixels());                }            }            else            { warning << "could not allocate memory or load image [" << filenames << "]" << POS; }        }        delete image;


The background image has a width of 1000 pixels, and is in this case white...
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
Quote:Original post by Decrius
*** Source Snippet Removed ***

The background image has a width of 1000 pixels, and is in this case white...

gltexSubImage2D copies part of an existing texture - not part of an image. You will need to crop to the part of the image you want (corona provides functions for this maybe?) before uploading it to OpenGL.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Hi! All,

Thanks for the reply. I think I didn't able to explain the problem...

Here is my new question...

Suppose, somewhere in my codes I have loaded an image as texture and now I know only the texture id.

Later, somwwhere in my codes I want to know the data (pixels), width and height of a texture provided an id (suppose 11 number texture).

Thanks in advance.
Make a struct with these variables and refer to that with a texture_id.
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
something like glGetTexImage(GL_TEXTURE_2D,0,GL_RGB,GL_UNSIGNED_BYTE,imagedata) will load texture data into the imagedata array ; the problem is that you need to know at least the pixelformat and the dimensions to get something usefull.
Here you go

glGetTexLevelParameter and make sure the texture object is bound first then call glGetTexLevelParameter with the parameters you are looking for. HTH

This topic is closed to new replies.

Advertisement