hehe, hope i can post code
/removed code, look at bottom/
What is strane is that it will not draw the triangle, and only displays a black screen, why?
thanks
[This message has been edited by Rulz (edited 03-08-2002).]
hehe, hope i can post code
/removed code, look at bottom/
What is strane is that it will not draw the triangle, and only displays a black screen, why?
thanks
[This message has been edited by Rulz (edited 03-08-2002).]
You are using PFD_DOUBLEBUFFER so you need to swap buffers in your draw function.
strange, still doesn’t work:
} else {
DrawGLScene();
SwapBuffers(hDC); //new
}
just a black screen
Instead of putting SwapBuffers(); after DrawGLScene(); try putting it in place of glFlush();.
Also try it without the glTranslatef(0.0f, 0.0f, -6.0f);.
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#define myClearScreen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
#define mySwap SwapBuffers(hDC);
#define myReset glLoadIdentity();
// Function Declarations
LRESULT CALLBACK
WndProc( HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam );
VOID EnableOpenGL( HWND hWnd, HDC * hDC, HGLRC * hRC );
VOID DisableOpenGL( HWND hWnd, HDC hDC, HGLRC hRC );
GLfloat rtri;
int resulutionx=800;
int resulutiony=600;
//Extra Functions (to tiden up the code)
int InitGL(GLvoid) //Init code in here
{
glShadeModel(GL_SMOOTH); //Smooth Shading
glClearColor(0.7f,0.5f,0.5f,1.0f);
glClearDepth(1.0f); //Depth of clearing
glEnable(GL_DEPTH_TEST); //Enable depth test
glDepthFunc(GL_LEQUAL); //type of testing
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); //nicest perspective correction
glMatrixMode(GL_PROJECTION); //projection matrix
return 1;
}
int DrawGLScene(GLvoid) // Here’s Where We Do All The Drawing
{
myClearScreen;
glColor3f(1.0, 0.3, 0.0);
myReset;
glRotatef(rtri,0.0f,1.0f,0.0f);
glBegin(GL_TRIANGLES); // Start Drawing A Triangle
glColor3f(1.0f,0.0f,0.0f); // Set Top Point Of Triangle To Red
glVertex3f( 0.0f, 1.0f, 0.0f); // First Point Of The Triangle
glColor3f(0.0f,1.0f,0.0f); // Set Left Point Of Triangle To Green
glVertex3f(-1.0f,-1.0f, 0.0f); // Second Point Of The Triangle
glColor3f(0.0f,0.0f,1.0f); // Set Right Point Of Triangle To Blue
glVertex3f( 1.0f,-1.0f, 0.0f); // Third Point Of The Triangle
glEnd();
rtri+=0.2f;
return 1;
}
int WINAPI
WinMain( HINSTANCE hInstance , HINSTANCE hPrevInstance , LPSTR lpCmdLine , int iCmdShow )
{
WNDCLASS wc;
HWND hWnd;
HDC hDC;
HGLRC hRC;
MSG msg;
BOOL bQuit = FALSE;
float theta = 0.0f;
wc.style = CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
wc.lpszMenuName = NULL;
wc.lpszClassName = “GLSample”;
RegisterClass( &wc );
if (MessageBox(NULL,“Do ya want hi-res?”, “Hi-res?”,MB_YESNO|MB_ICONQUESTION)==IDYES)
{
resulutionx=1024;
resulutiony=768; // Windowed Mode
}
hWnd = CreateWindow( “GLSample”, “OpenGL Sample”, WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE, 0, 0, resulutionx , resulutiony , NULL, NULL, hInstance, NULL );
EnableOpenGL( hWnd, &hDC, &hRC );
InitGL();
while ( !bQuit ) {
// check for messages
if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) {
// handle or dispatch messages
if ( msg.message == WM_QUIT ) {
bQuit = TRUE;
} else {
TranslateMessage( &msg );
DispatchMessage( &msg );
}
} else {
DrawGLScene();
mySwap;
}
}
// shutdown OpenGL
DisableOpenGL( hWnd, hDC, hRC );
// destroy the window explicitly
DestroyWindow( hWnd );
return msg.wParam;
}
// Window Procedure
LRESULT CALLBACK
WndProc( HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam )
{
switch ( message ) {
case WM_CREATE:
return 0;
case WM_CLOSE:
PostQuitMessage( 0 );
return 0;
case WM_DESTROY:
return 0;
case WM_KEYDOWN:
switch ( wParam ) {
case VK_ESCAPE:
PostQuitMessage( 0 );
return 0;
}
return 0;
default:
return DefWindowProc( hWnd,
message, wParam, lParam );
}
}
// Enable OpenGL
VOID EnableOpenGL( HWND hWnd, HDC * hDC, HGLRC * hRC )
{
PIXELFORMATDESCRIPTOR pfd;
int iFormat;
// get the device context (DC)
*hDC = GetDC( hWnd );
// set the pixel format for the DC
ZeroMemory( &pfd, sizeof( pfd ) );
pfd.nSize = sizeof( pfd );
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
iFormat = ChoosePixelFormat( *hDC, &pfd );
SetPixelFormat( *hDC, iFormat, &pfd );
// create and enable the render context (RC)
*hRC = wglCreateContext( *hDC );
wglMakeCurrent( *hDC, *hRC );
}
// Disable OpenGL
VOID DisableOpenGL( HWND hWnd, HDC hDC, HGLRC hRC )
{
wglMakeCurrent( NULL, NULL );
wglDeleteContext( hRC );
ReleaseDC( hWnd, hDC );
}
strange, now animation won’t work (I can display and create things)it almost seems like it is stuck at frame one, i will do some more testing to narrow the problem down if i can
[This message has been edited by Rulz (edited 03-08-2002).]