Advertisement

Not Rendering...

Started by January 17, 2002 05:28 PM
7 comments, last by Vlion 23 years, 1 month ago
Hi all. I`ve been working on my 4d engine, and I`ve been using glut. After while I needed more flexibility, so I(ofc course) dropped by NeHe`s site to get my w32 code. It compiles fine. It runs fine...execpt... I cant get it to render. glClearColor works for sure. Everything else, as far as I know, does not work on the GL end. This code is based on the NeHe code, but I`ve modified parts of it to fit my needs. Thank you, ~V''lion

//as far as i can tell everything should work !!!

#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <fstream>
#include <math.h>
#include <time.h>
#include <ctype.h>

#include <gl/gl.h>
#include <gl/glaux.h>
#include <gl/glu.h>

#include "c3Point.h"
#include "c4Point.h"
#include "c4PointC.h"
#include "cEngine2API.h"
#include "c4Light.h"

using namespace std;

//DELETE/RECODE !
#define SCRNX 800
#define SCRNY 600

LRESULT	CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);	// Declaration For WndProc
void Mouse(int,int,int,int);
void Special(int,int,int);
int Keys();
void KillGLWindow();
bool CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag);



bool fscrn;

bool bp;

int fcount;
float frate;

time_t diff;
time_t start;

char obuff[64];


HDC			hDC=NULL;		// Private GDI Device Context
HGLRC		hRC=NULL;		// Permanent Rendering Context
HWND		hWnd=NULL;		// Holds Our Window Handle
HINSTANCE	hInstance;		// Holds The Instance Of The Application

bool keys[256];			// Array Used For The Keyboard Routine

static bool	active = true;		// Window Active Flag Set To true By Default
static bool done = false;
bool fullscreen;


#define VERTS 3
c4PointC vert[VERTS];
cEngine2API e2a;

class CAMERA
{
private:		
	fstream cpos;
public:
	
	float px, py, pz;
	float tx, ty, tz;
	
	//Routine to write current camera position
	//It would be cleaner to have the open/shutdown code in the constructor/desctuctor, but
	//this way if it jams, the file isnt left open.
	void WritePos()
	{
		cpos.open("cameraposition.txt",ios::app);
		cpos << "\nlocation" << "\nX:" << tx << " Y:" << ty << " Z:" << tz;
		cpos << "\nangle" << "\nX:" << px << " Y:" << py << " Z:" << pz;
		cpos.close();
	}
	
};
CAMERA CAM;



//Default value loaded to 100.
//Inludes a glBegin/End block
void DrawAxes(int len = 100)
{
	Vertex4 p1(0,0,0,len);
	Vertex4 p2(0,0,0,-len);
	Vertex3 temp;
	glBegin(GL_LINES);
	{
		//X axis. Red color.
		glColor3f(1,0,0);
		glVertex3f(len,0,0);
		glVertex3f(-len,0,0);
		
		//Y axis. Green color.
		glColor3f(0,1,0);
		glVertex3f(0,len,0);
		glVertex3f(0,-len,0);
		
		//Z axis. Blue color.
		glColor3f(0,0,1);
		glVertex3f(0,0,len);
		glVertex3f(0,0,-len);
		
		//W axis. White color.
		glColor3f(1,1,1);
		temp = p1.Perspect();
		glVertex3f(temp.x,temp.y,temp.z);
		
		temp = p2.Perspect();
		glVertex3f(temp.x,temp.y,temp.z);
		
		
	}
	glEnd();
	
}


bool Render ()
{    
	if(bp == true)
	{
		//I put a breakpoint here.
		bp = false;
	}
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	
	glClearColor(0,0,0,1);
	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	//	glTranslatef(CAM.tx,CAM.ty,CAM.tz);
	//	glRotatef(CAM.px,1,0,0);
	//	glRotatef(CAM.py,0,1,0);
	//	glRotatef(CAM.pz,0,0,1);
	
	DrawAxes();
	glColor3f(1,1,0);
	glVertex2f(-100,-100);
	glVertex2f(100,-100);
	glVertex2f(100,100);
	glVertex2f(-100,-100);
	
	glFlush();
	if(!SwapBuffers(hDC))					
	{
		KillGLWindow();
	}
	
	return true;
	
}

int SetupGL(GLvoid)										// All Setup For OpenGL Goes Here
{
	
	glClearColor(0,0,0,0);
	glViewport(0,0,SCRNX,SCRNY);
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	
	gluPerspective(60.0f, SCRNX/SCRNY, 1.0, 1000.0f);
	glShadeModel(GL_SMOOTH);
	
	glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
	
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
	
	//Backface culling
	/*
	glFrontFace(GL_CW);	//CCW + GL_BACK work, CW and GL_FRONT work
	glCullFace(GL_FRONT);
	glEnable(GL_CULL_FACE);*/
	
	
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	return true;										// Initialization Went OK
}

int Init(int argc,char **argv)
{
	//DELETE/REPLACE
	
	
	glTranslatef(-45,-15,-40);
	
	
	vert[0].Set(5,0,0,0);
	
	vert[0].SetC(.5,.5,.5,1);
	
	vert[1].Set(-5,0,0,0);
	
	vert[1].SetC(.5,.5,.5,1);
	
	vert[2].Set(0,5,0,0);
	
	vert[2].SetC(.5,.5,.5,1);
	
	CAM.px = CAM.py = CAM.pz = 0;
	
	CAM.tx = CAM.ty = CAM.tz = 0;
	
	bp = false;
	
	
	fcount = 0;
	obuff[64];
	time_t start = 0L;
	
	return 0;
}

int Main()
{
	
	// Increment the frame count
	fcount++;
	
	//I picked this time code up and reworked it.
	if(start == 0)
	{
		start = clock();
	}
	else
	{
		diff = clock() - start;
		
		//Yes, casts are needed.
		frate = (float)(fcount) / ((float)(diff) / 1000.0f);
		
		// Initialize frame rate display
		sprintf(obuff,"Bugle4D: %3.1f fps",frate);
		
		//////////////
	}
	if(!active)
	{
		done = true;							// ESC or Render Signalled A Quit
	}
	if(!Render())
	{
		done = true;
	}
	
	Keys();
	return true;
	
}



void KillGLWindow()								// Properly Kill The Window
{
	if (fullscreen)										// Are We In Fullscreen Mode?
	{
		ChangeDisplaySettings(NULL,0);					// If So Switch Back To The Desktop
		ShowCursor(true);								// Show Mouse Pointer
	}
	
	if (hRC)											// Do We Have A Rendering Context?
	{
		if (!wglMakeCurrent(NULL,NULL))					// Are We Able To Release The DC And RC Contexts?
		{
			MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
		}
		
		if (!wglDeleteContext(hRC))						// Are We Able To Delete The RC?
		{
			MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
		}
		hRC=NULL;										// Set RC To NULL
	}
	
	if (hDC && !ReleaseDC(hWnd,hDC))					// Are We Able To Release The DC
	{
		MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
		hDC=NULL;										// Set DC To NULL
	}
	
	if (hWnd && !DestroyWindow(hWnd))					// Are We Able To Destroy The Window?
	{
		MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
		hWnd=NULL;										// Set hWnd To NULL
	}
	
	if (!UnregisterClass("OpenGL",hInstance))			// Are We Able To Unregister Class
	{
		MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
		hInstance=NULL;									// Set hInstance To NULL
	}
}


bool CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
{
	GLuint		PixelFormat;			// Holds The Results After Searching For A Match
	WNDCLASS	wc;						// Windows Class Structure
	DWORD		dwExStyle;				// Window Extended Style
	DWORD		dwStyle;				// Window Style
	RECT		WindowRect;				// Grabs Rectangle Upper Left / Lower Right Values
	WindowRect.left=(long)0;			// Set Left Value To 0
	WindowRect.right=(long)width;		// Set Right Value To Requested Width
	WindowRect.top=(long)0;				// Set Top Value To 0
	WindowRect.bottom=(long)height;		// Set Bottom Value To Requested Height
	
	fullscreen=fullscreenflag;			// Set The Global Fullscreen Flag
	
	hInstance			= GetModuleHandle(NULL);				// Grab An Instance For Our Window
	wc.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;	// Redraw On Size, And Own DC For Window.
	wc.lpfnWndProc		= (WNDPROC) WndProc;					// WndProc Handles Messages
	wc.cbClsExtra		= 0;									// No Extra Window Data
	wc.cbWndExtra		= 0;									// No Extra Window Data
	wc.hInstance		= hInstance;							// Set The Instance
	wc.hIcon			= LoadIcon(NULL, IDI_WINLOGO);			// Load The Default Icon
	wc.hCursor			= LoadCursor(NULL, IDC_ARROW);			// Load The Arrow Pointer
	wc.hbrBackground	= NULL;									// No Background Required For GL
	wc.lpszMenuName		= NULL;									// We Don''t Want A Menu
	wc.lpszClassName	= "OpenGL";								// Set The Class Name
	
	RegisterClass(&wc);								// Attempt To Register The Window Class
	
	if (fullscreen)												// Attempt Fullscreen Mode?
	{
		DEVMODE dmScreenSettings;								// Device Mode
		memset(&dmScreenSettings,0,sizeof(dmScreenSettings));	// Makes Sure Memory''s Cleared
		dmScreenSettings.dmSize=sizeof(dmScreenSettings);		// Size Of The Devmode Structure
		dmScreenSettings.dmPelsWidth	= width;				// Selected Screen Width
		dmScreenSettings.dmPelsHeight	= height;				// Selected Screen Height
		dmScreenSettings.dmBitsPerPel	= bits;					// Selected Bits Per Pixel
		dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
		
		if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
		{
			if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
			{
				fullscreen=false;		// Windowed Mode Selected.  Fullscreen = false
			}
			else
			{
				MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP);
				return false;									// Return false
			}
		}
	}
	
	if (fullscreen)												// Are We Still In Fullscreen Mode?
	{
		dwExnostyle=WS_EX_APPWINDOW;								// Window Extended Style
		dwnostyle=WS_POPUP;										// Windows Style
		ShowCursor(false);										// Hide Mouse Pointer
	}
	else
	{
		dwExnostyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;			// Window Extended Style
		dwnostyle=WS_OVERLAPPEDWINDOW;							// Windows Style
	}
	
	AdjustWindowRectEx(&WindowRect, dwStyle, false, dwExStyle);		// Adjust Window To true Requested Size
	
	if (!(hWnd=CreateWindowEx(	dwExStyle,							// Extended Style For The Window
								"OpenGL",							// Class Name
								title,								// Window Title
								dwStyle |							// Defined Window Style
								WS_CLIPSIBLINGS |					// Required Window Style
								WS_CLIPCHILDREN,					// Required Window Style
								0, 0,								// Window Position
								WindowRect.right-WindowRect.left,	// Calculate Window Width
								WindowRect.bottom-WindowRect.top,	// Calculate Window Height
								NULL,								// No Parent Window
								NULL,								// No Menu
								hInstance,							// Instance
								NULL)))								// Dont Pass Anything To WM_CREATE
	{
		KillGLWindow();								// Reset The Display
		return false;								// Return false
	}
	
	static	PIXELFORMATDESCRIPTOR pfd =				// pfd Tells Windows How We Want Things To Be
	{
		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 (!(hDC=GetDC(hWnd)))							// Did We Get A Device Context?
	{
		KillGLWindow();								// Reset The Display
		return false;								// Return false
	}
	
	if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd)))	// Did Windows Find A Matching Pixel Format?
	{
		KillGLWindow();								// Reset The Display
		return false;								// Return false
	}
	
	if(!SetPixelFormat(hDC,PixelFormat,&pfd))		// Are We Able To Set The Pixel Format?
	{
		KillGLWindow();								// Reset The Display
		return false;								// Return false
	}
	
	if (!(hRC=wglCreateContext(hDC)))				// Are We Able To Get A Rendering Context?
	{
		KillGLWindow();								// Reset The Display
		return false;								// Return false
	}
	
	if(!wglMakeCurrent(hDC,hRC))					// Try To Activate The Rendering Context
	{
		KillGLWindow();								// Reset The Display
		return false;								// Return false
	}
	
	ShowWindow(hWnd,SW_SHOW);						// Show The Window
	SetForegroundWindow(hWnd);						// Slightly Higher Priority
	SetFocus(hWnd);									// Sets Keyboard Focus To The Window
	if (WindowRect.bottom == 0)										// Prevent A Divide By Zero By
	{
		WindowRect.bottom = 1;
	}
	
	glViewport(0,0,WindowRect.right,WindowRect.bottom);						// Reset The Current Viewport
	
	glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix
	glLoadIdentity();									// Reset The Projection Matrix
	
	gluPerspective(45.0f,(GLfloat)WindowRect.bottom/(GLfloat)WindowRect.right,0.1f,100.0f);
	
	glMatrixMode(GL_MODELVIEW);							// Select The Modelview Matrix
	glLoadIdentity();									// Reset The Modelview Matrix
	
	if (!SetupGL())									// Initialize Our Newly Created GL Window
	{
		KillGLWindow();								// Reset The Display
		return false;								// Return false
	}
	
	return true;									// Success
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)		
{
	switch (uMsg)									// Check For Windows Messages
	{
	case WM_ACTIVATE:							// Watch For Window Activate Message
		{
			if (!HIWORD(wParam))					// Check Minimization State
			{
				active=true;						// Program Is Active
			}
			else
			{
				active=false;						// Program Is No Longer Active
			}
			
			return 0;								// Return To The Message Loop
		}
		
	case WM_SYSCOMMAND:							// Intercept System Commands
		{
			switch (wParam)							// Check System Calls
			{
			case SC_SCREENSAVE:	
				{
					break;
				}
			case SC_MONITORPOWER:				
				{
					break;
				}
				return 0;							
			}
			break;									// Exit
		}
		
	case WM_CLOSE:								// Did We Receive A Close Message?
		{
			PostQuitMessage(0);						// Send A Quit Message
			return 0;								// Jump Back
		}
		
	case WM_KEYDOWN:							// Is A Key Being Held Down?
		{
			keys[wParam] = true;					// If So, Mark It As true
			
			return 0;								// Jump Back
		}
		
	case WM_KEYUP:								// Has A Key Been Released?
		{
			keys[wParam] = false;					// If So, Mark It As false
			return 0;								// Jump Back
		}
		
	}
	
	// Pass All Unhandled Messages To DefWindowProc
	return DefWindowProc(hWnd,uMsg,wParam,lParam);
}

int WINAPI WinMain(	HINSTANCE	hInstance,			// Instance
				   HINSTANCE	hPrevInstance,		// Previous Instance
				   LPSTR		lpCmdLine,			// Command Line Parameters
				   int			nCmdShow)			// Window Show State
{
	MSG		msg;									// Windows Message Structure
	BOOL done = false;								// Bool Variable To Exit Loop
	
	fullscreen = false;							// Windowed Mode
	
	// Create Our OpenGL Window
	if (!CreateGLWindow("NeHe''s OpenGL Framework",SCRNY,SCRNY,16,fullscreen))
	{
		return 0;									// Quit If Window Was Not Created
	}
	
	while(!done)									// Loop That Runs While done=false
	{
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))	// Is There A Message Waiting?
		{
			if (msg.message == WM_QUIT)				// Have We Received A Quit Message?
			{
				done=true;							// If So done=true
			}
			else									// If Not, Deal With Window Messages
			{
				TranslateMessage(&msg);				// Translate The Message
				DispatchMessage(&msg);				// Dispatch The Message
			}
		}
		else										// If There Are No Messages
		{
			//This main is my working area.
			//WinMain/winproc handle W32 stuff
			Main();
			
		}
	}
	
	// Shutdown
	KillGLWindow();									// Kill The Window
	return (msg.wParam);							// Exit The Program
}







//HERE ON DOWN.
//RECODE TO W32. 
/*
void Mouse(int button, int state, int x, int y)
{

  if(button == GLUT_RIGHT_BUTTON)
  {
		if(state == GLUT_DOWN)
		{
		CAM.tz -= 100;
		glutPostRedisplay();
		}
		
		  }
		  else if(button == GLUT_LEFT_BUTTON)
		  {
		  if(state == GLUT_DOWN)
		  {
		  CAM.tz += 100;
		  glutPostRedisplay();
		  }
		  }
		  }
		  
			void Special(int key, int x, int y)
			{
			switch(key)
			{
			case GLUT_KEY_UP:
			{	
			CAM.ty-=5;
			glutPostRedisplay();
			break;
			}
			case GLUT_KEY_DOWN:
			{
			CAM.ty+=5;
			glutPostRedisplay();
			break;
			}
			
			  case GLUT_KEY_RIGHT:
			  {
			  CAM.tx-=5;
			  glutPostRedisplay();
			  
				break;
				}
				
				  case GLUT_KEY_LEFT:
				  {
				  CAM.tx+=5;
				  glutPostRedisplay();
				  break;
				  
					}
					
					  case GLUT_KEY_F1:
					  {
					  CAM.tz += 5;
					  break;
					  }
					  case GLUT_KEY_F2:
					  {
					  CAM.tz -= 5;
					  break;
					  }
					  case GLUT_KEY_F12:
					  {
					  CAM.WritePos();
					  break;
					  }
					  case GLUT_KEY_HOME:
					  {
					  vert[2].q++;
					  
						break;
						}
						case GLUT_KEY_END:
						{
						vert[2].q--;
						
						  break;
						  }
						  
							default:
							{
							glutPostRedisplay();
							break;
							}
							}
							}
							
*/
//2 kinds of kbd commands.
//ctrl+
//key
int Keys()
{	
	char opkey = 0;
	
	if(keys[VK_CONTROL])
	{
		//all ctrl keys go here
	}
	else
	{
		//What key is hit ?
		while(!keys[opkey])
		{
			opkey++;
		}
		keys[opkey] = false;
		opkey = tolower(opkey);
		switch(opkey)
		{
			//CENTER ADDINGS
		case ''r'':
			{
				CAM.py += 5;
				break;
			}
			
		case ''u'':
			{
				CAM.px += 5;
				break;
			}
			//CENTER DELETINGS
		case ''l'':
			{
				CAM.py -= 5;
				break;
			}
			
		case ''d'':
			{
				CAM.px -= 5;
				break;
			}
		case ''q'':
			{
				CAM.pz += 5;
				break;
			}
		case ''w'':
			{
				CAM.pz -= 5;
				break;
			}
			
			
			//Reset
		case VK_SPACE:
			{
				
				CAM.px = CAM.py = CAM.pz = 0;
				
				CAM.tx = CAM.ty = CAM.tz = 0;
				
				fscrn = false;
				break;
			}
			//ESC
		case VK_ESCAPE:
			{
				
				PostQuitMessage(0);
				break;
			}
			
		case ''p'':
			{
				bp = true;
				break;
			}
		case ''X'':
			{
				vert[0].Rotate(1,true,false,false,false);
				vert[1].Rotate(1,true,false,false,false);
				vert[2].Rotate(1,true,false,false,false);
				break;
			}
			
		case ''Y'':
			{
				vert[0].Rotate(1,false,true,false,false);
				vert[1].Rotate(1,false,true,false,false);
				vert[2].Rotate(1,false,true,false,false);
				break;
			}
			
		case ''Z'':
			{
				vert[0].Rotate(1,false,false,true,false);
				vert[1].Rotate(1,false,false,true,false);
				vert[2].Rotate(1,false,false,true,false);
				break;
			}
		case ''W'':
			{
				vert[0].Rotate(1,false,false,false,true);
				vert[1].Rotate(1,false,false,false,true);
				vert[2].Rotate(1,false,false,false,true);
				break;
			}
			
		case ''T'':
			{
				vert[0].Translate(0,0,0,0);
				vert[1].Translate(0,0,0,20);
				vert[2].Translate(0,0,20,20);
				break;
			}
			
		case ''S'':
			{
				vert[0].Scale(1.1f);
				vert[1].Scale(1.1f);
				vert[2].Scale(1.1f);
				break;
			}
		case VK_UP:
			{	
				CAM.ty-=5;
				break;
			}
		case VK_DOWN:
			{
				CAM.ty+=5;
				break;
			}
			
		case VK_RIGHT:
			{
				CAM.tx-=5;
				break;
			}
			
		case VK_LEFT:
			{
				CAM.tx+=5;
				break;
			}
			
			/*		case VK_F1:
			{
			CAM.tz += 5;
			break;
			}
			case VK_F2:
			{
			CAM.tz -= 5;
			break;
			}*/
		case VK_F12:
			{
				CAM.WritePos();
				break;
			}			
			
		case ''f'':
			{
				KillGLWindow();						// Kill Our Current Window
				
				fullscreen = !fullscreen;				// Toggle Fullscreen / Windowed Mode
				if(fullscreen == false)
				{
					if (!CreateGLWindow("bugle4D",SCRNX,SCRNY,16,fullscreen))
					{
						done = true;
					}
				}
				else
				{
					if (!CreateGLWindow("Bugle4D",640,480,16,fullscreen))
					{
						done = true;
					}
				}
				break;
			}
		default:
			{
				return 2;
				break;
			}
	}
	}
	return 0;
}

 
the bugle4D engine; a new dimension in graphics... [link]http://members.tripod.com/thefivelions/bugle4d/[/link]
~V'lionBugle4d
IMO this scene displays a little blue pixel in the center of the screen. You should look at it.

In fact, your quad does not display because you have neither a glBegin(GL_QUADS) nor the corresponding glEnd() !!
And even if they were here, you would not see the quad since its z is 0.0, and it is behind the field of view which accepts z values between 1.0 and 1000.0 (according to the call of gluPerspective).

Hope that helps...
Advertisement
I _know_ my mind was wozzy when I write that code.
Had to be. Only was I would missed the glEnd/Begin statements.
Blue pixel ?
I see no blue pixel...
Here is my new Render(), still no luck !

bool Render (){    	if(bp == true)	{		//I put a breakpoint here.		bp = false;	}	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		glClearColor(0,0,0,1);		glMatrixMode(GL_MODELVIEW);	glLoadIdentity();	glTranslatef(CAM.tx,CAM.ty,CAM.tz);	glRotatef(CAM.px,1,0,0);	glRotatef(CAM.py,0,1,0);	glRotatef(CAM.pz,0,0,1);		DrawAxes();	glBegin(GL_QUADS);		glColor3f(1,1,0);		glVertex3f(-100,-100, 10);		glVertex3f(100,-100,10);		glVertex3f(100,100,10);		glVertex3f(-100,-100,10);	glEnd();		glFlush();	if(!SwapBuffers(hDC))						{		KillGLWindow();	}		return true;	} 


the bugle4D engine;
a new dimension in graphics...
[link]http://members.tripod.com/thefivelions/bugle4d/[/link]
~V'lionBugle4d
The blue pixel might be in the center of the screen at the start of the program. laso, it could not be here (depends on the drivers/gfx card). It was just a clue.


On your new rendering method, it's a bit better, but it's still normal that you don't see anything


In OpenGL, as NeHe said :
quote:
The center of an OpenGL screen is 0.0f on the X and Y axis. To the left of center would be a negative number. To the right would be a positive number. Moving towards the top of the screen would be a positive number, moving to the bottom of the screen would be a negative number. Moving deeper into the screen is a negative number, moving towards the viewer would be a positive number.

So, to see your scene you have to set negative Z values.
But here the calls to glVertex3f set the Z value to +10, eg towards the viewer.

When you define a range from 1.0 to 1000.0, in fact it accepts Z values from -1.0 to -1000.0 if the camera does not move.

In fact, if you moved your camera on the z axis, it might work.

Edited by - vincoof on January 18, 2002 4:37:59 AM
I know what you are saying.
But, back when I was starting OGL, I realized that I could not see anything but blackscreen, so I wrote a routine to show something... that I could move around.
Its called DrawAxes(int length).
It draws x,y, and z axes, from -len to len.
It too does not work.

Think its a bad wgl call ?

Im 95% positive its not my vertex calls and my camera.

//Default value loaded to 100.//Inludes a glBegin/End blockvoid DrawAxes(int len = 100){	glBegin(GL_LINES);	{		//X axis. Red color.		glColor3f(1,0,0);		glVertex3f(len,0,0);		glVertex3f(-len,0,0);				//Y axis. Green color.		glColor3f(0,1,0);		glVertex3f(0,len,0);		glVertex3f(0,-len,0);				//Z axis. Blue color.		glColor3f(0,0,1);		glVertex3f(0,0,len);		glVertex3f(0,0,-len);	}	glEnd();	} 


the bugle4D engine;
a new dimension in graphics...
[link]http://members.tripod.com/thefivelions/bugle4d/[/link]
~V'lionBugle4d
Probably axis aren't drawn because of blending, lighting, or texture2d that you may use in the code.

try this:

      void DrawAxes(int len = 100){	  glPushAttrib(GL_ALL_ATTRIB_BITS);    glDisable(GL_BLEND);    glDisable(GL_TEXTURE_2D);    glDisable(GL_LIGHTING);    glEnable(GL_DEPTH_TEST);     glBegin(GL_LINES);			glColor3f(1,0,0);	glVertex3f(len,0,0);	glVertex3f(-len,0,0);			glColor3f(0,1,0);		glVertex3f(0,len,0);		glVertex3f(0,-len,0);					glColor3f(0,0,1);		glVertex3f(0,0,len);		glVertex3f(0,0,-len);     glEnd();  glPopAttrib();}      


P.S. Here you do not need {} inside glBegin()/glEnd(), but, of course, it's not an error!

P.S. ...Also if you think that your scene is behing the camera, you can use rotation by 180 degrees around X axis:
glRotated( 180, 1.0, 0.0, 0.0);
(or any other axis that is perpendicular to the direction of camera view)

Hope this helps


Edited by - Alex Bijamov on January 19, 2002 6:10:50 AM
Advertisement
If your camera is in the wrong place, you won't see anything.

That's the camera position which made me think you would see a blue pixel in the center of the screen : because if your camera is at the origin, you won't see the red and green axis (their depth is 0 : not in the field of view) and the blue axis is cutting through the center of the screen (X and Y at 0 is the center of the screen, but as the z goes from -len to +len there is some chance for the pixel to finish in the field of view).

The camera is the first thing you have to take care if you see a blank screen.

Edited by - vincoof on January 19, 2002 8:55:36 AM
To Vlion: You have probably already done it, but anyways: to check whether is the camera position wrong, try restoring the default view (i mean identity matrix):

      glPushMatrix(); glLoadIdentity(); gltranslated( 0.0, 0.0,-10.0);  //...your axis and cube drawing code goes here... glPopMatrix();    


if in this case you see quad and axis, then camera position was wrong!


Edited by - Alex Bijamov on January 19, 2002 9:47:50 AM
AhHAH
gluLookAt saved the day.
I havn`t used it in months, but i vaguely remembered this function where you could point to where you wanted to look...

btw, i didnt know that you could push/pop attribs. Thank you !

Thanx,
~V''lion


the bugle4D engine;
a new dimension in graphics...
[link]http://members.tripod.com/thefivelions/bugle4d/[/link]
~V'lionBugle4d

This topic is closed to new replies.

Advertisement