And I test like this. Do not use loadFromImage. create texture first, and then use update.
pimage = new sf::Image;
pimage->create(nWidth, nHeight, pdata);
pTexture->create(nWidth, nHeight);
pTexture->update(*pimage);
//int ret = pTexture->loadFromImage(*pimage);
pTexture->copyToImage().saveToFile("c:\\test5.jpg");
pimage->saveToFile("c:\\test6.jpg");
delete pimage;
But I find the pTexture is init failed.
if (!m_texture)
{
GLuint texture;
glCheck(glGenTextures(1, &texture));
m_texture = static_cast<unsigned int>(texture);
}
it can run into this area, but m_texture still 0.
if I test only SFML, without QT code, it run correctly.
sf::Texture* pbackgroundTexture = new sf::Texture;
pbackgroundTexture->create(800, 480);
pbackgroundTexture->update(*pbackgroundImage);
//pbackgroundTexture->loadFromImage(*pbackgroundImage);
delete pbackgroundImage;
pbackgroundTexture->copyToImage().saveToFile("c:\\test1.jpg");
In init part. I write like this:
m_pThread = new QUIThread(this);
m_pThread->Init();
m_pThread->start();
void QUIThread::Init() {
m_pGECase = new GraphEngineCase;
m_pGECase->SetThread(this);
m_pGECase->SetGraphEngine(m_pGECase);
m_pGECase->InitGraphEngine();
}
void GraphEngine::InitGraphEngine() {
QFile file(".\\GraphConfig.ini");
if (!file.open(QIODevice::ReadOnly)) {
return;
}
QTextStream in(&file);
QString info = file.readLine();
m_width = info.right(info.length() - info.indexOf(":") - 1).toInt();
info = file.readLine();
m_height = info.right(info.length() - info.indexOf(":") - 1).toInt();
file.close();
m_Settings.antialiasingLevel = 8;
m_Window.create(sf::VideoMode(m_width, m_height), "Tinading Simulator", sf::Style::Default, m_Settings);
m_Window.setFramerateLimit(50);
}
Failed to activate OpenGL context:
Failed to activate the window's context
An internal OpenGL call failed in Texture.cpp(746).
Expression:
glBindTexture(GL_TEXTURE_2D, texture->m_texture)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(772).
Expression:
glMatrixMode(GL_TEXTURE)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(773).
Expression:
glLoadMatrixf(matrix)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(776).
Expression:
glMatrixMode(GL_MODELVIEW)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in RenderTarget.cpp(711).
Expression:
glDrawArrays(mode, static_cast<GLint>(firstVertex), static_cast<GLsizei>(vertexCount))
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in TextureSaver.cpp(38).
Expression:
glGetIntegerv(GL_TEXTURE_BINDING_2D, &m_textureBinding)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(424).
Expression:
glBindTexture(GL_TEXTURE_2D, m_texture)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(425).
Expression:
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(426).
Expression:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(433).
Expression:
glFlush()
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in TextureSaver.cpp(45).
Expression:
glBindTexture(GL_TEXTURE_2D, m_textureBinding)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(746).
Expression:
glBindTexture(GL_TEXTURE_2D, texture->m_texture)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(772).
Expression:
glMatrixMode(GL_TEXTURE)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(773).
Expression:
glLoadMatrixf(matrix)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(776).
Expression:
glMatrixMode(GL_MODELVIEW)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in RenderTarget.cpp(711).
Expression:
glDrawArrays(mode, static_cast<GLint>(firstVertex), static_cast<GLsizei>(vertexCount))
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(472).
Expression:
glGetIntegerv(GLEXT_GL_READ_FRAMEBUFFER_BINDING, &readFramebuffer)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(473).
Expression:
glGetIntegerv(GLEXT_GL_DRAW_FRAMEBUFFER_BINDING, &drawFramebuffer)
Error description:
GL_INVALID_OPERATION
The specified operation Failed to activate OpenGL context:
Failed to activate the window's context
An internal OpenGL call failed in Texture.cpp(746).
Expression:
glBindTexture(GL_TEXTURE_2D, texture->m_texture)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(772).
Expression:
glMatrixMode(GL_TEXTURE)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(773).
Expression:
glLoadMatrixf(matrix)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(776).
Expression:
glMatrixMode(GL_MODELVIEW)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in RenderTarget.cpp(711).
Expression:
glDrawArrays(mode, static_cast<GLint>(firstVertex), static_cast<GLsizei>(vertexCount))
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in TextureSaver.cpp(38).
Expression:
glGetIntegerv(GL_TEXTURE_BINDING_2D, &m_textureBinding)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(424).
Expression:
glBindTexture(GL_TEXTURE_2D, m_texture)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(425).
Expression:
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(426).
Expression:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(433).
Expression:
glFlush()
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in TextureSaver.cpp(45).
Expression:
glBindTexture(GL_TEXTURE_2D, m_textureBinding)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(746).
Expression:
glBindTexture(GL_TEXTURE_2D, texture->m_texture)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(772).
Expression:
glMatrixMode(GL_TEXTURE)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(773).
Expression:
glLoadMatrixf(matrix)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(776).
Expression:
glMatrixMode(GL_MODELVIEW)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in RenderTarget.cpp(711).
Expression:
glDrawArrays(mode, static_cast<GLint>(firstVertex), static_cast<GLsizei>(vertexCount))
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(472).
Expression:
glGetIntegerv(GLEXT_GL_READ_FRAMEBUFFER_BINDING, &readFramebuffer)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(473).
Expression:
glGetIntegerv(GLEXT_GL_DRAW_FRAMEBUFFER_BINDING, &drawFramebuffer)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(478).
Expression:
GLEXT_glGenFramebuffers(1, &sourceFrameBuffer)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(479).
Expression:
GLEXT_glGenFramebuffers(1, &destFrameBuffer)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
Cannot copy texture, failed to create a frame buffer object
An internal OpenGL call failed in Texture.cpp(746).
Expression:
glBindTexture(GL_TEXTURE_2D, texture->m_texture)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(772).
Expression:
glMatrixMode(GL_TEXTURE)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(773).
Expression:
glLoadMatrixf(matrix)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(776).
Expression:
glMatrixMode(GL_MODELVIEW)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in RenderTarget.cpp(711).
Expression:
glDrawArrays(mode, static_cast<GLint>(firstVertex), static_cast<GLsizei>(vertexCount))
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(782).
Expression:
glBindTexture(GL_TEXTURE_2D, 0)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(785).
Expression:
glMatrixMode(GL_TEXTURE)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(786).
Expression:
glLoadIdentity()
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenGL call failed in Texture.cpp(789).
Expression:
glMatrixMode(GL_MODELVIEW)
Error description:
GL_INVALID_OPERATION
The specified operation is not allowed in the current state.