I write a OpenGL
code for Render Images on screen. I using GLUT
to create a window and callbacks but i want to render images in win32
window not in the GLUT
, basically we have a CreateWindowEx()
API to create window in win32
and we have a HWND
(handle) so that we can pass this handle to HDC
but i didn't find anything like this in GLUT
, is it possible to send handle to GLUT
? or other approach ?.
Below is my code its render images on screen successfully.
int main()
{
__try{
int argc = 1;
char *argv[1] = { (char*)"GLUTwindow" };
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(1024, 768);
glutInitWindowPosition(0, 0);
glutCreateWindow("GLUTwindow");
GLenum err = glewInit(); if (GLEW_OK != err) __debugbreak();
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMotionFunc(motion);
glutMainLoop();
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
}
return 0;
}
void init()
{
// compile and link the shaders into a program, make it active
vShader = compileShader(vertexShader, GL_VERTEX_SHADER);
fShader = compileShader(fragmentShader, GL_FRAGMENT_SHADER);
std::list<GLuint> tempList;
tempList.clear();
tempList.insert(tempList.end(), (GLuint)vShader);
tempList.insert(tempList.end(), (GLuint)fShader);
program = createProgram(tempList);
offset = glGetUniformLocation(program, "offset"); GLCHK;
texUnit = glGetUniformLocation(program, "texUnit"); GLCHK;
glUseProgram(program); GLCHK;
// configure texture unit
glActiveTexture(GL_TEXTURE0); GLCHK;
glUniform1i(texUnit, 0); GLCHK;
// create and configure the textures
glGenTextures(1, &texture); GLCHK;
// "Bind" the newly created texture : all future texture functions will modify this texture
glBindTexture(GL_TEXTURE_2D, texture); GLCHK;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); GLCHK;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); GLCHK;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); GLCHK;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); GLCHK;
}
void display()
{
GLuint w, h; std::vector<GLubyte> img; if (lodepng::decode(img, w, h, "test2.png")) __debugbreak();
glBindTexture(GL_TEXTURE_2D, texture); GLCHK;
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,w,h, 0, GL_RGBA, GL_UNSIGNED_BYTE, &img[0]); GLCHK;
glClear(GL_COLOR_BUFFER_BIT); GLCHK;
glBindTexture(GL_TEXTURE_2D, texture); GLCHK;
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); GLCHK;
glutSwapBuffers();
glutPostRedisplay();
}
wglCreateContext
is the name of a function you'll need. You'll also need to understand that GLUT usual stands between you and openGL. With that intermediary gone, you'll need to work a lot harder to achieve the same thing yourself without the help of many functions often taken for granted. Perhaps you'll find some use in solution #2 over here: codeproject.com/questions/672673/… – enhzflepwglCreateContext
it takes HDC. Thank you both @enhzflep and @BDL. – Krish