Hello !
I’m trying to use the function glCopyImageSubData for copying a 2D texture data from a context to another.
But the code crashes into a Segmentation Fault…
I was wondering if it’s related to my driver : my GPU is a NVIDIA Corporation GK104 [GeForce GTX 670] with the 340.96 driver installed (OPENGL version 4.4.0) . I’m on Ubuntu 14.04.
Here’s my code :
#include <cstdlib>
#include <iostream>
#include <GL/glew.h>
#include <GL/glut.h>
#include <GL/glext.h>
#include "SOIL/SOIL.h"
using namespace std;
GLuint tex, ctex;
int width, height;
void initTex(void){
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
//loading
unsigned char* image;
image = SOIL_load_image("/home/alien/sources/of_v0.9.3_linux64_release/apps/myApps/createOpenGLContext/dist/Debug/GNU-Linux/of0", &width, &height, 0, SOIL_LOAD_RGB);
if(image==0){
cout << "Image didn't loaded" << endl;
}
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
//Wrap Mode
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
//Filtering
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
cout << SOIL_last_result() << endl;
cout << "width = "<< width << endl;
cout << "height = "<< height << endl;
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
cout << "init Tex glError ? " << glGetError() << endl;
SOIL_free_image_data(image);
}
void copyTex(void){
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &ctex);
glBindTexture(GL_TEXTURE_2D, ctex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glBindTexture(GL_TEXTURE_2D, 0);
cout << "ctex id = " << ctex << endl;
try{
glCopyImageSubData(tex, GL_TEXTURE_2D, 0, 0, 0, 0, ctex, GL_TEXTURE_2D, 0, 0, 0, 0, width, height, 1);
cout << "MISSION COMPLETE "<<endl;
}
catch(int e) {
cout << "ERROR : " << glGetError() << " - exp " << e <<endl;
}
}
void init(void){
glClearColor(1, 1, 1, 1);
glShadeModel(GL_FLAT);
initTex();
copyTex();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
cout << "end of init : "<<glGetError() << endl;
}
void display(void){
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBindTexture(GL_TEXTURE_2D, tex);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3f(-1, 1, 0);
glTexCoord2f(0.0, 1.0); glVertex3f(-1, -1, 0);
glTexCoord2f(1.0, 1.0); glVertex3f(1, -1, 0);
glTexCoord2f(1.0, 0.0); glVertex3f(1, 1, 0);
glEnd();
glDisable(GL_TEXTURE_2D);
glFlush();
cout << "End of Display : glError ? " << glGetError() << endl;
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(256,256);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
Please let me know if i’m doing something wrong :)
Any tips or piece of advice is welcomed.
Cheers,
Masato