Jump to content
  • Advertisement

Colonel Spex

Member
  • Content Count

    18
  • Joined

  • Last visited

Community Reputation

125 Neutral

About Colonel Spex

  • Rank
    Member
  1. Colonel Spex

    Window Creation in Win 7

    It worked ! Buffer "0" it is ! :)   Thanks again Erik! I've since written compiled and load some simple 430 core shader code!   This is Awesome! Thanks!!   :D
  2. Colonel Spex

    Window Creation in Win 7

    ok thanks!   No worries about trying to help! Again, very much appreciated!   I'll simplify the code and try "0" in place of GL_DRAW_BUFFER0 later today.   Thanks again!
  3. Colonel Spex

    Window Creation in Win 7

    which begs the question, when SwapBuffers is called, Is it swapping in GL_DRAW_BUFFER0 ? and is it the same as GL_BACK and GL_FRONT as the msdn SwapBuffers doc page mentions...
  4. Colonel Spex

    Window Creation in Win 7

    Now my code looks like this but still a black window // Draw if ((char*)glGetString(GL_VERSION) != NULL) { //glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //0.8956f, 0.3451f, 0.2234f, 1.0f glClearBufferfv(GL_COLOR, GL_DRAW_BUFFER0, red); //ExitProcess(100); //<--- THIS EXITPROCESS RUNS } else { //glClearColor(0.8956f, 0.3451f, 0.2234f, 1.0f); glClearBufferfv(GL_COLOR, GL_DRAW_BUFFER0, red); //ExitProcess(100); } //glClear(GL_COLOR_BUFFER_BIT); SwapBuffers(hDC);
  5. Colonel Spex

    Window Creation in Win 7

    I've edited my code as below but still get a black screen... *sigh* if ((char*)glGetString(GL_VERSION) != NULL) { //glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //0.8956f, 0.3451f, 0.2234f, 1.0f glClearBufferfv(GL_COLOR, GL_DRAW_BUFFER0, red); //ExitProcess(100); //<--- THIS EXITPROCESS RUNS } else { //glClearColor(0.8956f, 0.3451f, 0.2234f, 1.0f); glClearBufferfv(GL_COLOR, GL_DRAW_BUFFER0, red); //ExitProcess(100); } glClear(GL_COLOR_BUFFER_BIT); SwapBuffers(hDC);
  6. Colonel Spex

    Window Creation in Win 7

    Thanks again Erik!   Yes I do have trouble with the details. I've been wanting to do what I am doing now for years but never had the time. And I still don't :) But I am trying now anyway. I'll do my best to check and recheck the opengl and MSDN docs!   I really do appreciate all your help!
  7. Colonel Spex

    Window Creation in Win 7

    Is there a more standard or general way to create windows in C++ ?
  8. Colonel Spex

    Window Creation in Win 7

    ok.   Here is some updated code. I added in the glewinit() section and found that it does return GLEW_OK but my function to color the buffer and display it either doesnt run or leaves the buffer empty to show a black window.   Further help? #include <windows.h> //#include <gl/gl.h> #include <GL/glew.h> //#include <GL/glut.h> #include <iostream> using namespace std; #pragma comment (lib, "opengl32.lib") LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); // Main int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { //ExitProcess(100); WNDCLASSEX wc = {}; wc.cbSize = sizeof(wc); wc.lpszClassName = TEXT("MyClass"); wc.hInstance = hInstance; wc.lpfnWndProc = WndProc; wc.style = CS_OWNDC; RegisterClassEx(&wc); // Window HWND hWnd = CreateWindowEx( 0, wc.lpszClassName, TEXT("OpenGL Window"), WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL ); // Get DC HDC hDC = GetDC(hWnd); // Pixel format PIXELFORMATDESCRIPTOR pfd = {}; pfd.nSize = sizeof(pfd); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_SUPPORT_COMPOSITION; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 32; int pf = ChoosePixelFormat(hDC, &pfd); SetPixelFormat(hDC, pf, &pfd); // OpenGL context HGLRC hGLRC = wglCreateContext(hDC); wglMakeCurrent(hDC, hGLRC); glewExperimental = GL_TRUE; GLenum err = glewInit(); if (err != GLEW_OK) { //Problem: glewInit failed, something is seriously wrong. cout << "glewInit failed, aborting." << endl; ExitProcess(100); //<-- this does not run. } // Get OpenGL version and set it as window title SetWindowTextA(hWnd, (char*)glGetString(GL_VERSION)); // test opengl // glCompileShader(GL_VERTEX_SHADER_FILE); static const GLfloat red[] = { 1.0f, 0.0f, 0.0f, 1.0 }; // Main loop ShowWindow(hWnd, nCmdShow); while (true) { MSG msg; if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) != 0) { if (msg.message == WM_QUIT) break; else { TranslateMessage(&msg); DispatchMessage(&msg); } } else { // Draw if ((char*)glGetString(GL_VERSION) != NULL) { //glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //0.8956f, 0.3451f, 0.2234f, 1.0f glClearBufferfv(GL_COLOR, 0, red); ExitProcess(100); //<--- THIS EXITPROCESS RUNS } else { //glClearColor(0.8956f, 0.3451f, 0.2234f, 1.0f); glClearBufferfv(GL_COLOR, 0, red); //ExitProcess(100); } glClear(GL_COLOR_BUFFER_BIT); SwapBuffers(hDC); } } // Clean up wglMakeCurrent(NULL, NULL); wglDeleteContext(hGLRC); UnregisterClass(wc.lpszClassName, hInstance); return 0; } // Window proc LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_DESTROY: PostQuitMessage(0); return 0; case WM_SIZE: // Resize GL rendering area to match window size glViewport(0, 0, LOWORD(lParam), HIWORD(lParam)); return 0; } return DefWindowProc(hWnd, msg, wParam, lParam); }
  9. Colonel Spex

    Window Creation in Win 7

    oh haha :P thanks again. :)
  10. Colonel Spex

    Window Creation in Win 7

    Hi Guys,   It's been a while but I've since been able to ( assumedly ) get glew working.. or maybe not because this code below crashes at runtime...   I am assuming the pointers didn't map correctly even tho the code compiles. Any have any advice? #include <windows.h> //#include <gl/gl.h> #include <GL/glew.h> //#include <GL/glut.h> #pragma comment (lib, "opengl32.lib") LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); // Main int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wc = {}; wc.cbSize = sizeof(wc); wc.lpszClassName = TEXT("MyClass"); wc.hInstance = hInstance; wc.lpfnWndProc = WndProc; wc.style = CS_OWNDC; RegisterClassEx(&wc); // Window HWND hWnd = CreateWindowEx( 0, wc.lpszClassName, TEXT("OpenGL Window"), WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL ); // Get DC HDC hDC = GetDC(hWnd); // Pixel format PIXELFORMATDESCRIPTOR pfd = {}; pfd.nSize = sizeof(pfd); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_SUPPORT_COMPOSITION; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 32; int pf = ChoosePixelFormat(hDC, &pfd); SetPixelFormat(hDC, pf, &pfd); // OpenGL context HGLRC hGLRC = wglCreateContext(hDC); wglMakeCurrent(hDC, hGLRC); // Get OpenGL version and set it as window title SetWindowTextA(hWnd, (char*)glGetString(GL_VERSION)); // test opengl // glCompileShader(GL_VERTEX_SHADER_FILE); static const GLfloat red[] = { 1.0f, 0.0f, 0.0f, 1.0 }; // Main loop ShowWindow(hWnd, nCmdShow); while (true) { MSG msg; if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) != 0) { if (msg.message == WM_QUIT) break; else { TranslateMessage(&msg); DispatchMessage(&msg); } } else { // Draw if ((char*)glGetString(GL_VERSION) != NULL) { //glClearColor(0.8956f, 0.3451f, 0.2234f, 1.0f); // <-- THIS LINE WORKS FINE 0.2345f, 0.7845f, 0.8934f, 1.0f glClearBufferfv(GL_COLOR, 0, red); // <-- THIS LINE CASUES A RUNTIME CRASH } else { glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //0.8956f, 0.3451f, 0.2234f, 1.0f } glClear(GL_COLOR_BUFFER_BIT); SwapBuffers(hDC); } } // Clean up wglMakeCurrent(NULL, NULL); wglDeleteContext(hGLRC); UnregisterClass(wc.lpszClassName, hInstance); return 0; } // Window proc LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_DESTROY: PostQuitMessage(0); return 0; case WM_SIZE: // Resize GL rendering area to match window size glViewport(0, 0, LOWORD(lParam), HIWORD(lParam)); return 0; } return DefWindowProc(hWnd, msg, wParam, lParam); }
  11. Colonel Spex

    Window Creation in Win 7

    Cool! Thanks!
  12. Colonel Spex

    Window Creation in Win 7

    So I checked GLEW and it looks like the tutorials suggest a use GLUT for window creation and handling.   I'd like to use as much windows code as possible. ( I am a linux sysadmin learning windows programming so I can use the practice :)   Is it possible to use the GLEW extensions with windows code like WndPrc and LRESULT CALLBACK functions?
  13. Colonel Spex

    Window Creation in Win 7

    Awesome! Thanks!
  14. Colonel Spex

    Window Creation in Win 7

    Wow Erik thats an Awesome reply! Thanks! Can you show me an example of how to use GLEW? I recall reading about GLEW as well and it was yet another peice I couldnt wrap my head around. :)
  15. Colonel Spex

    Window Creation in Win 7

    Thanks so much for all the sources guys! I've made quite a few windows so far. Now my next question... How do I configure a Microsoft window tomget out of the way and let me render using OpenGL ? I've been through a fair amount of sell research in OpenGL using the latest versions of the OpenGL superbible. And while some of the example code works, I can't seem to draw using OpenGL in windows I've created myself. I'd like to draw using OpenGL 4.5 but 4.3 seems to be the most recent version supported by most graphics cards. Thanks Again!
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!