PDA

View Full Version : glCopyImageSubData -> Fails and no glGetError message...



Masa_F
07-08-2016, 05:48 AM
Hi there,

I'm currently trying to develop an app for texture sharing on GPU (like spout/ syphon) but for linux. I'm using ubuntu 14.04, GPU : NVIDIA GeForce GTX 670 / OpenGL version 4.4.0 NVIDIA 340.96.
But I'm running into a problem : my code builds but crashes on the function glCopyImageSubData : Segmentation Fault : Core Dumped. And I don't know what's wrong...

Here's my code, which is quiet simple...
I'm using SOIL for loading a texture image.



#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;
}




I tried several things, like changing the format, internal format, type of textures objects, but no success.
Does anybody has a clue on what the problem is ? If someone could test my code, we could compare the result.
Thanks in advance :)

Masato