OpenGL texture to ImageMagick
OpenGL texture to ImageMagick
Is there possibility to get ImageMagick image from OpenGL texture? I'm developing OpenGL paint app. I'm using ImageMagick to load images and send them to OpenGL textures. Then OpenGL textures are being edited by user, and now I want to be able to save edited textures (opengl view) like image.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: OpenGL texture to ImageMagick
How are OpenGl textures stored?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: OpenGL texture to ImageMagick
Heres my whole code for loading textures
Code: Select all
- (void)uzkraunamImg
{
using namespace Magick;
input_image = strdup([[[NSBundle mainBundle] pathForResource:@"Brush" ofType:@"png"] UTF8String]);
image.read(input_image);
image.magick("RGBA");
image.write(&blob);
input_imageN = strdup([[[NSBundle mainBundle] pathForResource:@"grass" ofType:@"jpg"] UTF8String]);
imageN.read(input_imageN);
imageN.magick("RGBA");
imageN.write(&blobN);
imageG.read(input_imageN);
imageG.channel(GreenChannel);
imageG.magick("RGBA");
imageG.write(&blobG);
[self createTextures];
}
-(void)createTextures {
glGenTextures(1, &brushtxt);
glBindTexture(GL_TEXTURE_2D, brushtxt);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glGenerateMipmap(GL_TEXTURE_2D);
glGenTextures(1, &orgtxt);
glBindTexture(GL_TEXTURE_2D, orgtxt);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glGenerateMipmap(GL_TEXTURE_2D);
glGenTextures(1, &graytxt);
glBindTexture(GL_TEXTURE_2D, graytxt);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glGenerateMipmap(GL_TEXTURE_2D);
[self SetTextureImages];
}
- (void)SetTextureImages
{
glBindTexture(GL_TEXTURE_2D, brushtxt);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.columns(), image.rows(), 0, GL_RGBA, GL_UNSIGNED_BYTE, blob.data());
glBindTexture(GL_TEXTURE_2D, orgtxt);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageN.columns(), imageN.rows(), 0, GL_RGBA, GL_UNSIGNED_BYTE, blobN.data());
glBindTexture(GL_TEXTURE_2D, graytxt);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageG.columns(), imageG.rows(), 0, GL_RGBA, GL_UNSIGNED_BYTE, blobG.data());
}
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: OpenGL texture to ImageMagick
I am not that familar with OpenGl. I have used it to do some very basic stuff, but not textures.
However it looks like they are referencing some type of named resource in the form of JPG images. Whether that resource is built-in, or in some library directory, I have no idea. If you can get at the resource then I don't see IM having any problem.
If the resource is read in as a 'blob' (just a file in a byte array) then Im can read the 'blob' into its image structure for processing and back again.
However it looks like they are referencing some type of named resource in the form of JPG images. Whether that resource is built-in, or in some library directory, I have no idea. If you can get at the resource then I don't see IM having any problem.
If the resource is read in as a 'blob' (just a file in a byte array) then Im can read the 'blob' into its image structure for processing and back again.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/