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

  • Home
  • SEARCH
  • 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 4620946
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:37:47+00:00 2026-05-22T02:37:47+00:00

I’m currently trying to draw a quadratic surface with openGL.When using a single window,my

  • 0

I’m currently trying to draw a quadratic surface with openGL.When using a single window,my program can work well.Now I need a control panel so I create two windows,one is the frame window ,the other is the child window in which OpenGL runs.But the is something wrong with hidden-surface removal when openGL runs in the child window while this problem does not exist if I use single window.I didn’t change the drawing function,just get the dc of child window and set the rc.Here is the code.Thanks for help.

#include <windows.h> //Windows header
#include <gl\glut.h>                                    //glut
#include <gl\glaux.h>                                   //glaux
#define hID 6310                                        //ID of child window

LRESULT CALLBACK WndProc   (HWND, UINT, WPARAM, LPARAM) ;
LRESULT CALLBACK OpenProc (HWND, UINT, WPARAM, LPARAM) ;

TCHAR       szChildClass[] = TEXT ("OpenGL");     //child window class name
TCHAR       szAppName[] = TEXT ("Frame");         //frame window class name
HWND        hwndopen;                             //child window
handle
HWND        hwnd;                                 //frame window handle
MSG         msg ;                                 //message structure
HDC         hdc = NULL;                           //device context used in child window
HGLRC       hrc = NULL;                           //rendering context
HINSTANCE   hInstance;                            //application instance
GLuint      PixelFormat;                                //pixformat
BOOL        active=TRUE;                           
BOOL        keys[256];
float       rquad[3]={0,0,0};                     //angle of rotate    
// pfd Tells Windows How We Want Things To Be
static  PIXELFORMATDESCRIPTOR pfd={
sizeof(PIXELFORMATDESCRIPTOR),
1,PFD_DRAW_TO_WINDOW|
PFD_SUPPORT_OPENGL|
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,  
16,
0, 0, 0, 0, 0, 0,
0,0,0,0, 0, 0, 0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0 
};

/* Here I draw a color cube and I draw black line in every  edge
of the cube,the I draw 3 color lines to show x,y,z coordinate
axis*/
int DrawGLScene(void)                                   
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
glLoadIdentity();                                   
glTranslatef(0.0f,0.0f,-10.0f);                     
glRotatef(rquad[0],1.0f,0.0f,0.0f);                 
glRotatef(rquad[1],0.0f,1.0f,0.0f); 
glRotatef(rquad[2],0.0f,0.0f,1.0f);                 
glBegin(GL_QUADS);                                  
glColor3f(0.0f,1.0f,0.0f);                  
glVertex3f( 1.0f, 1.0f,-1.0f);                  
glVertex3f(-1.0f, 1.0f,-1.0f);                  
glVertex3f(-1.0f, 1.0f, 1.0f);                  
glVertex3f( 1.0f, 1.0f, 1.0f);              
glColor3f(1.0f,0.5f,0.0f);                      
glVertex3f( 1.0f,-1.0f, 1.0f);                  
glVertex3f(-1.0f,-1.0f, 1.0f);                  
glVertex3f(-1.0f,-1.0f,-1.0f);                  
glVertex3f( 1.0f,-1.0f,-1.0f);                  
glColor3f(1.0f,0.0f,0.0f);                      
glVertex3f( 1.0f, 1.0f, 1.0f);                  
glVertex3f(-1.0f, 1.0f, 1.0f);                  
glVertex3f(-1.0f,-1.0f, 1.0f);                  
glVertex3f( 1.0f,-1.0f, 1.0f);                  
glColor3f(1.0f,1.0f,0.0f);                      
glVertex3f( 1.0f,-1.0f,-1.0f);                  
glVertex3f(-1.0f,-1.0f,-1.0f);                  
glVertex3f(-1.0f, 1.0f,-1.0f);                  
glVertex3f( 1.0f, 1.0f,-1.0f);                  
glColor3f(0.0f,0.0f,1.0f);                      
glVertex3f(-1.0f, 1.0f, 1.0f);              
glVertex3f(-1.0f, 1.0f,-1.0f);                  
glVertex3f(-1.0f,-1.0f,-1.0f);                  
glVertex3f(-1.0f,-1.0f, 1.0f);                  
glColor3f(1.0f,0.0f,1.0f);                      
glVertex3f( 1.0f, 1.0f,-1.0f);                  
glVertex3f( 1.0f, 1.0f, 1.0f);                  
glVertex3f( 1.0f,-1.0f, 1.0f);                  
glVertex3f( 1.0f,-1.0f,-1.0f);                  
glEnd();                                            


glBegin(GL_LINES);
glColor3f(1.0f,1.0f,1.0f);
glVertex3f( 1.0f, 1.0f,-1.0f);                  
glVertex3f(-1.0f, 1.0f,-1.0f);                  
glVertex3f(-1.0f, 1.0f,-1.0f);                  
glVertex3f(-1.0f, 1.0f, 1.0f);                  
glVertex3f(-1.0f, 1.0f, 1.0f);                  
glVertex3f( 1.0f, 1.0f, 1.0f);              
glVertex3f( 1.0f, 1.0f,-1.0f);                  
glVertex3f( 1.0f, 1.0f, 1.0f);              
glVertex3f( 1.0f,-1.0f, 1.0f);              
glVertex3f(-1.0f,-1.0f, 1.0f);              
glVertex3f(-1.0f,-1.0f, 1.0f);                  
glVertex3f(-1.0f,-1.0f,-1.0f);                  
glVertex3f(-1.0f,-1.0f,-1.0f);                  
glVertex3f( 1.0f,-1.0f,-1.0f);                  
glVertex3f( 1.0f,-1.0f,-1.0f);                  
glVertex3f( 1.0f,-1.0f, 1.0f);                  
glVertex3f( 1.0f, 1.0f, 1.0f);                  
glVertex3f( 1.0f, -1.0f, 1.0f);             
glVertex3f( -1.0f, 1.0f, 1.0f);             
glVertex3f( -1.0f, -1.0f, 1.0f);                
glVertex3f( -1.0f, 1.0f, -1.0f);                
glVertex3f( -1.0f, -1.0f, -1.0f);               
glVertex3f( 1.0f, 1.0f, -1.0f);             
glVertex3f( 1.0f, -1.0f, -1.0f);                
glEnd();    
glBegin(GL_LINES);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f( 0.0f, 0.0f, 0.0f);  
glVertex3f( 10.0f, 0.0f, 0.0f);
glColor3f(1.0f,1.0f,0.0f);
glVertex3f( 0.0f, 0.0f, 0.0f);
glVertex3f( 0.0f, 10.0f, 0.0f);
glColor3f(1.0f,0.0f,1.0f);
glVertex3f( 0.0f, 0.0f, 0.0f);
glVertex3f( 0.0f, 0.0f, 10.0f);
glEnd();    
return TRUE;                                        
}


BOOL InitGL(void)                                       //init opengl
{
glShadeModel(GL_SMOOTH);                            // Enable Smooth Shading
glClearColor(1.0f,0.0f,1.0f,0.5f);
   glClearDepth(1.0f);                              glEnable(GL_DEPTH_TEST);                            glDepthFunc(GL_LEQUAL);                         glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
   return TRUE;
}

// resize the opengl scene in child window
void ReSizeGLScene(int width, int height)
{
 if (height==0)   //avoid zero to be the divisor 
                            {
    height=1;
}
glViewport(0,0,(int)width,(int)height);         
glMatrixMode(GL_PROJECTION);                        
glLoadIdentity();                                   
gluPerspective(45.0f,(float)width/(float)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);                         
glLoadIdentity();                               
}



int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                PSTR szCmdLine, int iCmdShow)
{


WNDCLASS     wndclass ;
BOOL         flag=TRUE;
hInstance    = GetModuleHandle(NULL);
InitGL();

wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc   = WndProc ;
wndclass.cbClsExtra    = 0 ;
wndclass.cbWndExtra    = 0 ;
wndclass.hInstance     = hInstance ;
wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
wndclass.lpszMenuName  = NULL ;
wndclass.lpszClassName = szAppName ;

if (!RegisterClass(&wndclass))                                  
{
MessageBox(NULL,"窗口类注册失败","演示程序 ",MB_OK|MB_ICONINFORMATION);
    return 0;
}
wndclass.lpfnWndProc   = OpenProc ;
wndclass.cbWndExtra    = sizeof (long) ;
wndclass.hIcon         = NULL ;
wndclass.hbrBackground = NULL;
wndclass.lpszClassName = szChildClass ;

if (!RegisterClass(&wndclass))                                  
{
    MessageBox(NULL,"子窗口类注册失败","演示程序",MB_OK|MB_ICONINFORMATION);
    return 0;
}

if(!(hwnd = CreateWindow (szAppName, TEXT ("Frisa"),
    WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, CW_USEDEFAULT,
    CW_USEDEFAULT, CW_USEDEFAULT,
    NULL, NULL, hInstance, NULL)))
{
    MessageBox(NULL,"窗口创建失败","演示程序",MB_OK|MB_ICONINFORMATION);
    return FALSE;                           
}

ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;

while (flag)
{
    if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
    {
        if (msg.message==WM_QUIT)           
        {
            if (!UnregisterClass(szChildClass,hInstance))           
            {
                MessageBox(NULL,"子窗口类注销失败","演示程序",MB_OK | MB_ICONINFORMATION);
                hInstance=NULL;                                 
            }

            if (!UnregisterClass(szAppName,hInstance))          
            {
                MessageBox(NULL,"窗口类注销失败","演示程序",MB_OK | MB_ICONINFORMATION);
                hInstance=NULL;                             
            }
            flag=FALSE;
        }
        else                                    
        {
            TranslateMessage(&msg);             
            DispatchMessage(&msg);              
        }
    }
    else
    {
        if (active && !DrawGLScene())   // Active?  Was There A Quit Received?
        {
            flag=FALSE;                         // ESC or DrawGLScene Signalled A Quit
        }
        else                                    // Not Time To Quit, Update Screen
        {

            SwapBuffers(hdc);                   // Swap Buffers (Double Buffering)
        }
        if(keys[VK_RIGHT]){rquad[0]+=0.12;}
        if(keys[VK_LEFT]){rquad[0]=0;rquad[1]=0;rquad[2]=0;}
        if(keys[VK_UP]){rquad[1]+=0.12;}
        if(keys[VK_DOWN]){rquad[2]+=0.12;}
    }
}

return msg.wParam ;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{

int   cxBlock, cyBlock;

switch (message)
{
case WM_CREATE :
    if(!(hwndopen= CreateWindow (szChildClass, NULL,
        WS_CHILDWINDOW | WS_VISIBLE,
        0, 0, 0, 0,
        hwnd,(HMENU)(hID),
        (HINSTANCE)GetWindowLong (hwnd, GWL_HINSTANCE),
        NULL)))
    {
        MessageBox(NULL,"子窗口创建失败","演示程序",MB_OK|MB_ICONINFORMATION);
        return 0;                               
    }
    if (!(hdc=GetDC(hwndopen)))                         
    {               
        MessageBox(NULL,"设备描述表创建失败","演示程序",MB_OK|MB_ICONINFORMATION);
        return 0;
    }

    if (!(PixelFormat=ChoosePixelFormat(hdc,&pfd)))
    {               
        MessageBox(NULL,"未找到匹配的像素格式","演示程序",MB_OK|MB_ICONINFORMATION);
        return 0;
    }

    if(!SetPixelFormat(hdc,PixelFormat,&pfd))   
    {               
        MessageBox(NULL,"设置像素格式失败","演示程序",MB_OK|MB_ICONINFORMATION);
        return 0;
    }

    if (!(hrc=wglCreateContext(hdc)))           
    {               
        MessageBox(NULL,"获取渲染描述表失败","演示程序",MB_OK|MB_ICONINFORMATION);
        return 0;
    }

    if(!wglMakeCurrent(hdc,hrc))                
    {               
        MessageBox(NULL,"渲染描述表激活失败","演示程序",MB_OK|MB_ICONINFORMATION);
        return 0;
    }
    return 0 ;

case WM_ACTIVATE:                           // Watch For Window Activate Message
    // LoWord Can Be WA_INACTIVE, WA_ACTIVE, WA_CLICKACTIVE,
    // The High-Order Word Specifies The Minimized State Of The Window Being Activated Or Deactivated.
    // A NonZero Value Indicates The Window Is Minimized.
    if ((LOWORD(wParam) != WA_INACTIVE) && !((BOOL)HIWORD(wParam)))
        active=TRUE;                        // Program Is Active
    else
        active=FALSE;                       // Program Is No Longer Active
    return 0;                               // Return To The Message Loop

case WM_SIZE :
    cxBlock = LOWORD (lParam);
    cyBlock = HIWORD (lParam);
    MoveWindow (hwndopen,
        5,5,
        (int)(cxBlock*0.80),(int)(cyBlock*0.98), TRUE) ;
    ReSizeGLScene((int)(cxBlock*0.80),(int)(cyBlock*0.97));
    return 0 ;

case WM_LBUTTONDOWN :
    MessageBeep (0) ;
    return 0 ;

case WM_KEYDOWN:                
    keys[wParam] = TRUE;                
    return 0;                       

case WM_KEYUP:                              
    keys[wParam] = FALSE;
    return 0;

case WM_CLOSE:
    DestroyWindow(hwnd);
    return 0;

case WM_DESTROY :
    if (hrc)                                            
    {
        if (!wglMakeCurrent(hdc,NULL))
        {
            MessageBox(NULL,"DC和RC关联解除失败","演示程序",MB_OK | MB_ICONINFORMATION);
        }

        if (!wglDeleteContext(hrc)) 
        {
            MessageBox(NULL,"RC释放失败","演示程序",MB_OK | MB_ICONINFORMATION);
        }

        hrc=NULL;
    }

    if (!DestroyWindow(hwnd))   
    {
        MessageBox(NULL,"窗口句柄释放失败","演示程序",MB_OK | MB_ICONINFORMATION);
        hwnd=NULL;  
    }

    PostQuitMessage (0) ;
    return 0 ;

}
return DefWindowProc (hwnd, message, wParam, lParam) ;
  }

LRESULT CALLBACK OpenProc (HWND hwnd, UINT message, 
                       WPARAM wParam, LPARAM lParam)
{
return DefWindowProc (hwnd, message, wParam, lParam) ;
}

ADDITION

My aim is to paint a clolor cube in the child window with OpenGL.The size of the child window is about 0.8 times the frame window’s size.I will add a control panel in the rest of area of the frame window. My program can draw a color cube .But the problem is I can see all the 6 faces,and all the 12 edges of the cube.I’m not sure but it looks like the hidden-surface removal failed.

Here I provide a link to the image of the result.
http://svgeqg.blu.livefilestore.com/y1p_TRCQ495hxOztZy3oi5qZiDPdN9hQil0KLTY9I-7fFfqCuVr_FiyJ-dIlflN5eHCMqZo5smpUwTaFDxAelq_rjO5hTU5kVzS/colorcube.JPG?psid=1

  • 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-05-22T02:37:47+00:00Added an answer on May 22, 2026 at 2:37 am

    I have solved the problem,it’s about the location of the OpenGL initialization.The initializationmust be after the creation of the child window in which OpenGL runs.In the above code,I init OpenGL at the beginning of winmain() function ,but the child window does not exist at that time.

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

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
I want use html5's new tag to play a wav file (currently only supported
I have a JSP page retrieving data and when single or double quotes are
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.