Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8055673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:27:43+00:00 2026-06-05T08:27:43+00:00

I’m trying to make my first polygon. Because I wrote a code, complied it

  • 0

I’m trying to make my first polygon.

Because I wrote a code, complied it and voila … the triangle is not displayed 🙁

What is wrong with this code?

#pragma once

#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <gl\GL.h>
#include <gl\glu.h>
#include <gl\glut.h>

HDC         hDC=NULL;
HGLRC       hRC=NULL;

GLvoid GL_ReSizeGLScene(GLsizei width, GLsizei height);
int GL_init( GLvoid );
int GL_drawit( GLvoid );

typedef struct {
    HWND hWnd;
} Glab_t;

static Glab_t glab;

char szClassName[ ] = "GLab";

static LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
    switch (message) {
        case WM_DESTROY:
            PostQuitMessage (0);
            break;
        case WM_SIZE:
            GL_ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));
            break;
        default:
            return DefWindowProc (hwnd, message, wParam, lParam);
    }
    return 0;
}


int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
    MSG messages;
    RECT rect;
    WNDCLASSEX wndClass;
    int screenWidth, screenHeight;
    int x, y, w, h;
    GLuint      PixelFormat;

    screenWidth = GetSystemMetrics(SM_CXSCREEN);
    screenHeight = GetSystemMetrics(SM_CYSCREEN);

    rect.left = (screenWidth - 582) / 2;
    rect.top = (screenHeight - 358) / 2;
    rect.right = rect.left + 582;
    rect.bottom = rect.top + 358;

    x = rect.left;
    y = rect.top;
    w = 640;
    h = 480;


    wndClass.hInstance = hInstance;
    wndClass.lpszClassName = szClassName;
    wndClass.lpfnWndProc = WindowProcedure;
    wndClass.style = CS_DBLCLKS;
    wndClass.cbSize = sizeof (WNDCLASSEX);
    wndClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wndClass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
    wndClass.lpszMenuName = NULL;
    wndClass.cbClsExtra = 0;
    wndClass.cbWndExtra = 0;
    wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);

    if (!RegisterClassEx (&wndClass)) {
        return 0;
    }

    glab.hWnd = CreateWindowEx (
           0,
           szClassName,
           "GLab - OpenGL",
           WS_OVERLAPPEDWINDOW,
           x,
           y,
           w,
           h,
           HWND_DESKTOP,
           NULL,
           hInstance,
           NULL 
           );

    static  PIXELFORMATDESCRIPTOR pfd=  {
        sizeof(PIXELFORMATDESCRIPTOR),
        1,
        PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
        PFD_TYPE_RGBA,
        16, // Can be 32 tough :)
        0, 0, 0, 0, 0, 0,
        0,
        0,
        0,
        0, 0, 0, 0, 
        16, 
        0,
        0,
        PFD_MAIN_PLANE, 
        0,
        0, 0, 0 
    };

    if (!(hDC=GetDC(glab.hWnd))) {
        MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
        return FALSE;
    }

    if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) {
        MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
        return FALSE;
    }

    if(!SetPixelFormat(hDC,PixelFormat,&pfd)) {
        MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
        return FALSE;
    }

    if (!(hRC=wglCreateContext(hDC))) {
        MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
        return FALSE;
    }

    if(!wglMakeCurrent(hDC,hRC)) {
        MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
        return FALSE;
    }

    ShowWindow (glab.hWnd, nCmdShow);
    SetForegroundWindow(glab.hWnd);
    SetFocus(glab.hWnd);
    GL_ReSizeGLScene( w, h );

    if (!GL_init() ) {
        MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);
        return false;
    }

    if( !GL_drawit() ) {
        MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);
        return false;
    }

    while (GetMessage (&messages, NULL, 0, 0)) {
        TranslateMessage(&messages);
        DispatchMessage(&messages);
    }

    return messages.wParam;
}

GLvoid GL_ReSizeGLScene(GLsizei width, GLsizei height) {
    if (height==0) {
        height=1;
    }

    glViewport(0,0,width,height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}

int GL_init( GLvoid ) {
    glShadeModel(GL_SMOOTH);
    glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
    glClearDepth(1.0f);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    return true;
}

int GL_drawit( GLvoid ) {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glTranslatef(-1.5f,0.0f,-6.0f);
    glBegin(GL_TRIANGLES);
        glVertex3f( 0.0f, 1.0f, 0.0f);
        glVertex3f(-1.0f,-1.0f, 0.0f);
        glVertex3f( 1.0f,-1.0f, 0.0f);
    glEnd();            
    return true;
}

Using MC Visual C++ 2010 Express and OpenGL 1.4.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T08:27:48+00:00Added an answer on June 5, 2026 at 8:27 am

    You need a SwapBuffers() call in there after you render your scene:

    #include <Windows.h>
    #include <GL/GL.h>
    #include <GL/GLU.h>
    
    HDC         hDC=NULL;
    HGLRC       hRC=NULL;
    
    GLvoid GL_ReSizeGLScene(GLsizei width, GLsizei height);
    int GL_init( GLvoid );
    int GL_drawit( GLvoid );
    
    typedef struct {
        HWND hWnd;
    } Glab_t;
    
    static Glab_t glab;
    
    char szClassName[ ] = "GLab";
    
    static LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
        switch (message) {
            case WM_DESTROY:
                PostQuitMessage (0);
                break;
            case WM_SIZE:
                GL_ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));
                break;
            default:
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
        return 0;
    }
    
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
        MSG messages;
        RECT rect;
        WNDCLASSEX wndClass;
        int screenWidth, screenHeight;
        int x, y, w, h;
        GLuint      PixelFormat;
    
        screenWidth = GetSystemMetrics(SM_CXSCREEN);
        screenHeight = GetSystemMetrics(SM_CYSCREEN);
    
        rect.left = (screenWidth - 582) / 2;
        rect.top = (screenHeight - 358) / 2;
        rect.right = rect.left + 582;
        rect.bottom = rect.top + 358;
    
        x = rect.left;
        y = rect.top;
        w = 640;
        h = 480;
    
    
        wndClass.hInstance = hInstance;
        wndClass.lpszClassName = szClassName;
        wndClass.lpfnWndProc = WindowProcedure;
        wndClass.style = CS_DBLCLKS;
        wndClass.cbSize = sizeof (WNDCLASSEX);
        wndClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
        wndClass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
        wndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
        wndClass.lpszMenuName = NULL;
        wndClass.cbClsExtra = 0;
        wndClass.cbWndExtra = 0;
        wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
    
        if (!RegisterClassEx (&wndClass)) {
            return 0;
        }
    
        glab.hWnd = CreateWindowEx (
               0,
               szClassName,
               "GLab - OpenGL",
               WS_OVERLAPPEDWINDOW,
               x,
               y,
               w,
               h,
               HWND_DESKTOP,
               NULL,
               hInstance,
               NULL 
               );
    
        static  PIXELFORMATDESCRIPTOR pfd=  {
            sizeof(PIXELFORMATDESCRIPTOR),
            1,
            PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
            PFD_TYPE_RGBA,
            16, // Can be 32 tough :)
            0, 0, 0, 0, 0, 0,
            0,
            0,
            0,
            0, 0, 0, 0, 
            16, 
            0,
            0,
            PFD_MAIN_PLANE, 
            0,
            0, 0, 0 
        };
    
        if (!(hDC=GetDC(glab.hWnd))) {
            MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
            return FALSE;
        }
    
        if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) {
            MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
            return FALSE;
        }
    
        if(!SetPixelFormat(hDC,PixelFormat,&pfd)) {
            MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
            return FALSE;
        }
    
        if (!(hRC=wglCreateContext(hDC))) {
            MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
            return FALSE;
        }
    
        if(!wglMakeCurrent(hDC,hRC)) {
            MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
            return FALSE;
        }
    
        ShowWindow (glab.hWnd, nCmdShow);
        SetForegroundWindow(glab.hWnd);
        SetFocus(glab.hWnd);
        GL_ReSizeGLScene( w, h );
    
        if (!GL_init() ) {
            MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);
            return false;
        }
    
        while (GetMessage (&messages, NULL, 0, 0)) {
            TranslateMessage(&messages);
            DispatchMessage(&messages);
    
            if( !GL_drawit() ) {
                MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);
                return false;
            }
            SwapBuffers(hDC);
        }
    
        return messages.wParam;
    }
    
    GLvoid GL_ReSizeGLScene(GLsizei width, GLsizei height) {
        if (height==0) {
            height=1;
        }
    
        glViewport(0,0,width,height);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    }
    
    int GL_init( GLvoid ) {
        glShadeModel(GL_SMOOTH);
        glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
        glClearDepth(1.0f);
        glEnable(GL_DEPTH_TEST);
        glDepthFunc(GL_LEQUAL);
        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
        return true;
    }
    
    int GL_drawit( GLvoid ) {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glLoadIdentity();
        glTranslatef(-1.5f,0.0f,-6.0f);
        glBegin(GL_TRIANGLES);
            glVertex3f( 0.0f, 1.0f, 0.0f);
            glVertex3f(-1.0f,-1.0f, 0.0f);
            glVertex3f( 1.0f,-1.0f, 0.0f);
        glEnd();            
        return true;
    }
    

    EDIT: I also moved your GL_drawit() call to the event loop so it redraws in response to resize events. Well, any event at all really.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.