MyClass::paintGL()
{
glClear( GL_COLOR_BUFFER_BIT );
glDisable(GL_DEPTH_TEST);
unsigned int testWidth = 256;
unsigned int testHeight = 10496;
unsigned int testBpp = 16;
unsigned int colorIncr = (65536/testWidth);
unsigned short* testPattern = new unsigned short[testWidth*testHeight];
unsigned int color = 0;
for(unsigned int i = 0; i < testWidth*testHeight; ++i){
testPattern[i] = color;
color += colorIncr;
if(color >= 65536)
color = 0;
}
if(useOpenGL){
//OpenGL method: doesn't work
GLvoid* pixels = (GLushort*)testPattern;
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
GLuint myFrameTexture;
glGenTextures(1, &myFrameTexture);
glBindTexture(GL_TEXTURE_2D, (myFrameTexture));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE,
testWidth, testHeight,
0, GL_LUMINANCE, GL_UNSIGNED_SHORT, pixels);
float startX = 0.0f;
float startY = 0.0f;
float endX = testWidth;
float endY = testheight;
glBegin(GL_QUADS);
glTexCoord2f(0.0,1.0);
glVertex2f(startX, startY);
glTexCoord2f(0.0,0.0);
glVertex2f(startX, endY);
glTexCoord2f(1.0,0.0);
glVertex2f(endX, endY);
glTexCoord2f(1.0,1.0);
glVertex2f(endX, startY);
glEnd();
glDisable(GL_TEXTURE_2D);
glDeleteTextures(1, &myFrameTexture);
}else{
//QPainter method, also doesn't work.
p.scale(testWidth, testHeight);
image->setNumColors(256);
for(int i = 0; i < 256; i++)
image->setColor(i, QRGB(i,i,i));
//get 8bpp version of test pattern
unsigned char* test8bpp = new unsigned char[testHeight*testWidth];
for(int i = 0; i < (testHeight*testWidth); i++){
test8bpp[i] = testPattern[i] >> 8;
}
for(int i = 0; i < testHeight; i++){
unsigned char* row = image->scanLine(i);
memcpy(row, test8bpp+(i*testWidth), testWidth);
}
p.drawImage(0,0,*image);
delete [] test8bpp;
}
delete [] testPattern;
}
MyClass::paintGL()
{
glClear( GL_COLOR_BUFFER_BIT );
glDisable(GL_DEPTH_TEST);
unsigned int testWidth = 256;
unsigned int testHeight = 10496;
unsigned int testBpp = 16;
unsigned int colorIncr = (65536/testWidth);
unsigned short* testPattern = new unsigned short[testWidth*testHeight];
unsigned int color = 0;
for(unsigned int i = 0; i < testWidth*testHeight; ++i){
testPattern[i] = color;
color += colorIncr;
if(color >= 65536)
color = 0;
}
if(useOpenGL){
//OpenGL method: doesn't work
GLvoid* pixels = (GLushort*)testPattern;
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
GLuint myFrameTexture;
glGenTextures(1, &myFrameTexture);
glBindTexture(GL_TEXTURE_2D, (myFrameTexture));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE,
testWidth, testHeight,
0, GL_LUMINANCE, GL_UNSIGNED_SHORT, pixels);
float startX = 0.0f;
float startY = 0.0f;
float endX = testWidth;
float endY = testheight;
glBegin(GL_QUADS);
glTexCoord2f(0.0,1.0);
glVertex2f(startX, startY);
glTexCoord2f(0.0,0.0);
glVertex2f(startX, endY);
glTexCoord2f(1.0,0.0);
glVertex2f(endX, endY);
glTexCoord2f(1.0,1.0);
glVertex2f(endX, startY);
glEnd();
glDisable(GL_TEXTURE_2D);
glDeleteTextures(1, &myFrameTexture);
}else{
//QPainter method, also doesn't work.
QPainter p(this);
p.scale(testWidth, testHeight);
QImage* image = new QImage(testWidth, testHeight,
QImage::Format_Indexed8);
image->setNumColors(256);
for(int i = 0; i < 256; i++)
image->setColor(i, QRGB(i,i,i));
//get 8bpp version of test pattern
unsigned char* test8bpp = new unsigned char[testHeight*testWidth];
for(int i = 0; i < (testHeight*testWidth); i++){
test8bpp[i] = testPattern[i] >> 8;
}
for(int i = 0; i < testHeight; i++){
unsigned char* row = image->scanLine(i);
memcpy(row, test8bpp+(i*testWidth), testWidth);
}
p.drawImage(0,0,*image);
delete [] test8bpp;
}
delete [] testPattern;
}
To copy to clipboard, switch view to plain text mode
Bookmarks