Hello

I already posted this on opengl.org, but nobody seems to have a solution.
Basically I set up Opengl and when I want to draw 3D or say I want to use the z-axis by translating in this dimension, it doesn't have any effect.
What I can do, is moving my view in x and y axis, but not z.

I coded this with this
Here is my code :

(code is given chronologically)

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
				   LPSTR lpCmdLine, int iCmdShow)
{

        WNDCLASS wincl;
	HWND hWnd;
	MSG msg;

        wincl.hInstance = hInstance;
	wincl.lpszClassName = "GLEngine";
	wincl.lpfnWndProc = WndProc;
	wincl.style = 0;
	wincl.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MAINICON));
	wincl.hCursor = LoadCursor(NULL, IDI_APPLICATION);
	wincl.lpszMenuName = NULL;
	wincl.cbClsExtra = 0;
	wincl.cbWndExtra = 0;
	wincl.hbrBackground = NULL;
	if (!RegisterClass(&wincl)) return 0;


    app->setInstance(hInstance);

    if (!app->initAPI()) return 0;

    bool done = false;

    app->init();

    while (!app->isDone()) {

       //...

    }
}
bool OpenGLApp::initAPI()
{
    
    if (width < 640)
    width = 640;
    if (height < 480)
    height = 480;

    int monitorCounter = screen;
	EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, (LPARAM) &monitorCounter);

    int x, y;

	x = monInfo.rcMonitor.left;
	y = monInfo.rcMonitor.top;

	#ifdef DEBUG // For testing only

	std::ofstream myfile ("Info.txt");
	if (myfile.is_open())
    {
        myfile << monInfo.rcMonitor.left << "\n" << monInfo.rcMonitor.top << "\n";
        myfile << monInfo.rcMonitor.right << "\n" << monInfo.rcMonitor.bottom << "\n";
        myfile.close();
    }

    #endif

    DWORD flags = WS_CLIPCHILDREN | WS_CLIPSIBLINGS; ///< Set only one render-target

    if (Fullscreen)
    {
        flags = WS_POPUP;
        x = 0;
        y = 0;

        width = monInfo.rcMonitor.right;
        height = monInfo.rcMonitor.bottom;

        // change resolution before the window is created
        DEVMODE dmode;

        memset(&dmode, 0, sizeof(DEVMODE));// clear all memory
        dmode.dmSize=sizeof(DEVMODE);	   // it's required to specify the size of this struct
        dmode.dmPelsWidth = width;	   // width and height of desired resolution
        dmode.dmPelsHeight = height;
        dmode.dmBitsPerPel = cBits;	   // color depth; 8/16/32 bit
        dmode.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

        // change resolution, if possible
        if (ChangeDisplaySettings(&dmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
        {
            // if not... failed to change resolution
            flags = WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_OVERLAPPEDWINDOW;
            MessageBox(hWnd, "No Fullscreen mode is avaible.\nBack to windowed",
                         "Error", MB_OK);
        }
    }

    if (!Fullscreen)
    {
        flags |= WS_OVERLAPPEDWINDOW;
    }

    // create main window
	hWnd = CreateWindow(
		"GLEngine", getTitle(),
		flags,
		x, y, getWidth(), getHeight(),
		HWND_DESKTOP, NULL, hInstance, NULL );

    // number of available formats
    int indexPixelFormat = 0;

    PIXELFORMATDESCRIPTOR pfd =
    {
        sizeof(PIXELFORMATDESCRIPTOR),
        1,
        PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER,
        PFD_TYPE_RGBA, cBits,
        0,0,0,0,0,0,0,0,0,0,0,0,0, // useles parameters
        depthBits, stencilBits,
		0, PFD_MAIN_PLANE,0,0,0,0
    };

	hDC = GetDC( hWnd );

	if (hDC == 0)
	{
	     MessageBox(hWnd, "Failed to Get the Window Device Context",
                         "Device Context Error", MB_OK);
        return false;
	}

    // Choose the closest pixel format available
    indexPixelFormat = ChoosePixelFormat(hDC, &pfd);

    // Set the pixel format for the provided window DC
    SetPixelFormat(hDC, indexPixelFormat, &pfd);

	// create and enable the render context (RC)
	glContext = wglCreateContext( hDC );
	if (glContext == 0)
	{
	    MessageBox(hWnd, "Failed to Create the OpenGL Rendering Context",
                         "OpenGL Rendering Context Error", MB_OK);
        return false;
	}
	wglMakeCurrent( hDC, glContext );

	glEnable(GL_DEPTH_TEST);

	return true;

}
bool OpenGLApp::init()
{
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_NORMALIZE);
    glEnable(GL_COLOR_MATERIAL);

    return true;
}

And the action is done with the following code :

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    //glMatrixMode(GL_PROJECTION);
    //glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    //m_Camera.Render(); // Apply Camera viewport

        static float t = 0;


        //glRotatef(t,1,1,1);
        //glTranslatef(0,0,0.05*t);

        glBegin(GL_QUADS);

            glNormal3f(0.0, 1.0f, 0.0f);
            glColor3f(1.0,0.0,0.0); glVertex3f(0.0f, 0.0f, 0.0f);
            glVertex3f(1.0f, 0.0f, 0.0f);
            glVertex3f(1.0f, -1.0f, 0.0f);
            glColor3f(0.0,1.0,0.0); glVertex3f(0.0f, -1.0f, 0.0f);

        glEnd();

        t+=1;

        if (t > 360)
        {
            t = t - 360;
        }

    glFlush();
    SwapBuffers(hDC);

Now, as stated in the post at Opengl.org the polygon only appears when z is between -1 and 1.
When I do let it rotate it's shown 3D-like, but at some points there appears a black cut and a part of the quad isn't drawn.
Thats really odd what's happening.
If somebody could tell me what I'm missing to do, in order to draw 3D correctly, I'd be happy.

Here is my project if interested : www.megaupload.com/?d=DXLPV0BD

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.