• Advertisement
Sign in to follow this  

Texture from another texture

This topic is 3675 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Here you go

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement