PDA

View Full Version : OpenGL.... BANG BANG BANG BANG BANG



beakie
08-25-2012, 04:17 PM
The code executes without any errors thrown but nothing is drawn on the screen?

Any ideas, please?




#include "frmDeviceRender.h"

void FrmDeviceRender::setFormDefaults() {
setFormProperties(0, WS_OVERLAPPEDWINDOW , CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, TEXT("Rendered Container"));
};

void FrmDeviceRender::onPaint() {
hdc = GetDC (me) ;

GLsizei width = 200;
GLsizei height = 200;
int bits = 32;
GLuint PixelFormat;
static PIXELFORMATDESCRIPTOR pfd=
{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
1, // Version Number
PFD_DRAW_TO_WINDOW | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
bits, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
0, // No Alpha Buffer
0, // Shift Bit Ignored
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
16, // 16Bit Z-Buffer (Depth Buffer)
0, // No Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};

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

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

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

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

glClearColor (0.0, 0.0, 0.0, 0.0);
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
glBegin(GL_POLYGON);
glVertex3f (0.25, 0.25, 0.0);
glVertex3f (0.75, 0.25, 0.0);
glVertex3f (0.75, 0.75, 0.0);
glVertex3f (0.25, 0.75, 0.0);
glEnd();
glFlush();

ReleaseDC (me, hdc) ;
}

void FrmDeviceRender::onUnload() {
PostQuitMessage (0);
};

Rosario Leonardi
08-25-2012, 05:22 PM
You destroy the context before anything is send to the video card. Why you create and destroy the context every frame?

beakie
08-25-2012, 05:29 PM
This my first ever code using OpenGL. Worrying about frames must come later :)

What do I do to send something to the video card, please?

beakie
08-25-2012, 05:37 PM
This my first ever code using OpenGL. Worrying about frames must come later :)

What do I do to send something to the video card, please?

Found it


SwapBuffers(hdc); // Swap Buffers (Double Buffering)

Rosario Leonardi
08-25-2012, 05:40 PM
The code looks correct but consider that when you create a openGL context you are asking the driver to create a communication buffer between your program and the video card and to reserve some buffer where your program can write. Also to improve performance openGL context put your command in a queue, then (on glFlush, or any other frame finish command or when the queue is full) it send the command to the video card.
The command are then executed.. but you destroy the context, with buffer, queue and everything.
You are also using double buffer, so even if you wait to the command to be executed (glFinish) you are drawing on an hidden buffer that you have to show (SwapBuffers).


Here you can find some example on how to draw a basic scene.
http://nehe.gamedev.net/tutorial/lessons_01__05/22004/

or the wiki kickstart page (it's a little more advanced)
http://www.opengl.org/wiki/Getting_started#OpenGL_Context_Creation

beakie
08-25-2012, 10:16 PM
Thanks for this.

This is where I am now...
http://www.opengl.org/discussion_boards/showthread.php/178860-My-First-Code-Not-Updating?goto=newpost