示例#1
0
void CMassView::Draw(BRect updateRect)												//	draw the view
	{
	if (!inGLMode)
		{
		//DrawBitmap(theBlitMap, updateRect, updateRect);								//	blit the bits
		return;
		} // end of simple case
	else
		{
		LockGL();																	//	lock in preparation for drawing
		GLfloat mNow[16];															//	local matrix for ball routines							
		Ball_Update(&ball);															//	update the data for the ball								
		Ball_Value(&ball, mNow);													//	retrieve the ball's position as a matrix						
		glMatrixMode(GL_MODELVIEW);													//	make sure that we are set to the model matrix				
		glClearColor(0.0, 0.0, 0.0, 1.0);											//	and set the "clear" colour to black						
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);							//	clear the window to black								
		glPushMatrix();																//	push the GL stack to get a new matrix						
		glLoadIdentity();															//	load the identity matrix								
		glTranslatef(0, 0, -600.0);													//	translate the model matrix									
		glMultMatrixf(mNow);														//	multiply by this matrix								
		glEnable(GL_TEXTURE_2D);													//	enable 2D textures
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);				//	set the vertical (?) wrap
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);				//	and the horizontal
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);			//	set magnification filter
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);			//	set shrinking filter
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, theBlitMap->Bounds().Width() + 1, theBlitMap->Bounds().Height() + 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, theBlitMap->Bits());
		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);				//	just stick the texture on		
		glBindTexture(GL_TEXTURE_2D, texName);										//	bind the texture to the name (again?)
		glCallList(torusDisplayListID);												// and call the display list							
		glPopMatrix();																//	pop the matrix back off the stack
		SwapBuffers();																//	swap the buffers to draw it
		glDisable(GL_TEXTURE_2D);													//	switch textures back off
		UnlockGL();																	//	unlock GL
		} // end of GL case	
	} // end of Draw()
示例#2
0
void
learnView::AttachedToWindow()
{
	BGLView::AttachedToWindow();
	LockGL();

	glClearColor(0.0, 0.0, 0.0, 0.0);
	glShadeModel(GL_FILL);
//	glShadeModel(GL_SMOOTH);
	//glEnable(GL_DEPTH_TEST);
	//glEnable(GL_BLEND);
	//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glViewport( 0, 0, (GLsizei)Bounds().Width(), (GLsizei)Bounds().Height() );
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
	glMatrixMode(GL_MODELVIEW);

	UnlockGL();

	// start a thread to compute the board generations
	lifeTID = spawn_thread((thread_entry)lifeThread, "lifeThread", 
							B_NORMAL_PRIORITY, this);
	resume_thread(lifeTID);

	// start a thread which does all of the drawing
	drawTID = spawn_thread((thread_entry)drawThread, "drawThread",
								B_NORMAL_PRIORITY, this);
	resume_thread(drawTID);

	// Start 'er up!
	continuous = true;
	Start();
}
示例#3
0
/*	FUNCTION:		ViewBook :: DragDropImage
	ARGUMENTS:		texture_id
					mouse_x
					mouse_y
	RETURN:			true if source ownership acquired
	DESCRIPTION:	Hook function called when user drags/drops image to app window	
*/
bool ViewBook :: SurfaceUpdate(MediaSource *source, float mouse_x, float mouse_y)
{
	Paper::TEXTURE_SIDE side = Paper::UNASSIGNED_TEXTURE;
	Paper *page = GetPage(mouse_x, mouse_y, (int *)&side);
	
	LockGL();
	int index = -1;
	if (page == fPages[PAGE_LEFT])
		index = 0;
	else if (page == fPages[PAGE_RIGHT])
		index = 3;
	else if (page == fPages[PAGE_MIDDLE])
	{
		if (side == Paper::FRONT_TEXTURE)
			index = 1;
		else if (side == Paper::BACK_TEXTURE)
			index = 2;
	}
	if (index >= 0)
	{
		if (fMediaSources[index] != GetDefaultMediaSource())
			delete fMediaSources[index];
	} 
	page->SetMediaSource(side, source);
	fMediaSources[index] = source;
	UnlockGL();
	
	return true;
}
示例#4
0
	virtual void Render() {
		printf("Render\n");
		LockGL();
		//game_->run();
		SwapBuffers(true);
		UnlockGL();
	}
示例#5
0
/*	FUNCTION:		ViewObject :: GLCreateTexture
	ARGUMENTS:		bitmap
	RETURN:			OpenGL texture reference
	DESCRIPTION:	Create an OpenGL texture from a BBitmap.
					The client takes ownership of the create media source.
*/
void ViewObject :: GLCreateTexture(MediaSource *media, BBitmap *bitmap)
{
	assert(media != 0);
	assert(bitmap != 0);
	
	LockGL();
	glGenTextures(1, &media->mTextureID);
	glBindTexture(GL_TEXTURE_2D, media->mTextureID);
	
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	int num_bytes;
	GLDetermineFormat(bitmap->ColorSpace(), &media->mTextureFormat, &num_bytes);
	media->mTextureWidth = (int)(bitmap->Bounds().Width() + 1);
	media->mTextureHeight = (int)(bitmap->Bounds().Height() + 1);
	glTexImage2D(GL_TEXTURE_2D,
				0, 									// mipmap level
				num_bytes,							// internal format
				media->mTextureWidth,				// width
				media->mTextureHeight,				// height
				0,									// border
				media->mTextureFormat,				// format of pixel data
				GL_UNSIGNED_BYTE,					// data type
				(unsigned char *)bitmap->Bits());	// pixels
	UnlockGL();
}
示例#6
0
/*	FUNCTION:		ViewBook :: AttachedToWindow
	ARGUMENTS:		none
	RETURN:			n/a
	DESCRIPTION:	Hook function called when view attached to window (looper)
*/
void ViewBook :: AttachedToWindow(void)
{
	ViewObject::AttachedToWindow();
	
	LockGL();
	glClearColor(0,0,0,1);
	
	fPages[PAGE_MIDDLE] = new Paper(kPageWidth, kPageHeight, Paper::FRONT_AND_BACK_FACING);
	fPages[PAGE_LEFT] = new Paper(kPageWidth, kPageHeight, Paper::FRONT_FACING);
	fPages[PAGE_RIGHT] = new Paper(kPageWidth, kPageHeight, Paper::BACK_FACING);
	
	for (int i=0; i < NUMBER_SOURCES; i++)
		fMediaSources[i] = GetDefaultMediaSource();
	
	MediaSource *default_source = GetDefaultMediaSource();
	//	left page
	fPages[PAGE_LEFT]->SetMediaSource(Paper::FRONT_TEXTURE, fMediaSources[0]);
	//	middle page
	fPages[PAGE_MIDDLE]->SetMediaSource(Paper::FRONT_TEXTURE, fMediaSources[1]);
	fPages[PAGE_MIDDLE]->SetMediaSource(Paper::BACK_TEXTURE, fMediaSources[2]);
	//	right page
	fPages[PAGE_RIGHT]->SetMediaSource(Paper::BACK_TEXTURE, fMediaSources[3]);
	fPages[PAGE_RIGHT]->SetAngle(180);
	
	UnlockGL();
}	
示例#7
0
void SampleGLView::Render(void)
{
    LockGL();
    gDraw(rotate);
    SwapBuffers();
    UnlockGL();
}
示例#8
0
int
ObjectView::ObjectAtPoint(const BPoint &point)
{
	LockGL();
	glShadeModel(GL_FLAT);
	glDisable(GL_LIGHTING);
	glDisable(GL_FOG);
	glClearColor(black[0], black[1], black[2], 1.0);
	glClear(GL_COLOR_BUFFER_BIT | (fZbuf ? GL_DEPTH_BUFFER_BIT : 0));

	float idColor[3];
	idColor[1] = idColor[2] = 0;
	for (int i = 0; i < fObjects.CountItems(); i++) {
		// to take into account 16 bits colorspaces,
		// only use the 5 highest bits of the red channel
		idColor[0] = (255 - (i << 3)) / 255.0;
		reinterpret_cast<GLObject*>(fObjects.ItemAt(i))->Draw(true, idColor);
	}
	glReadBuffer(GL_BACK);
	uchar pixel[256];
	glReadPixels((GLint)point.x, (GLint)(Bounds().bottom - point.y), 1, 1,
		GL_RGB, GL_UNSIGNED_BYTE, pixel);
	int objNum = pixel[0];
	objNum = (255 - objNum) >> 3;

	EnforceState();
	UnlockGL();

	return objNum;
}
示例#9
0
/*	FUNCTION:		ViewObject :: UpdateFrame
	ARGUMENTS:		source
	RETURN:			n/a
	DESCRIPTION:	Called by Video thread - update video texture	
*/
void ViewObject :: UpdateFrame(MediaSource *source)
{
	LockGL();
	glBindTexture(GL_TEXTURE_2D, source->mTextureID);	
	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, source->mTextureWidth, source->mTextureHeight,
					 source->mTextureFormat, GL_UNSIGNED_BYTE, source->mVideo->GetBitmap()->Bits());
	UnlockGL();
}
示例#10
0
/*	FUNCTION:		ViewObject :: ToggleWireframe
	ARGUMENTS:		enable
	RETURN:			n/a
	DESCRIPTION:	Switch beteeen wireframe and fill polygon modes
*/
void ViewObject :: ToggleWireframe(bool enable)
{
	LockGL();
	if (enable)
		glPolygonMode(GL_FRONT, GL_LINE);
	else
		glPolygonMode(GL_FRONT, GL_FILL);
	UnlockGL();
}
示例#11
0
void SampleGLView::AttachedToWindow(void)
{
    BGLView::AttachedToWindow();
    LockGL();
    gInit();
    gReshape(width, height);
    UnlockGL();
    MakeFocus();
}
示例#12
0
/*	FUNCTION:		ViewBook :: Render
	ARGUMENTS:		none
	RETURN:			n/a
	DESCRIPTION:	Draw view contents	
*/
void ViewBook :: Render(void)
{
	LockGL();
	
	bigtime_t	current_time = real_time_clock_usecs();
	bigtime_t	delta = current_time - fStartTime;	
	fStartTime = current_time;
		
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	//	page freefall (gravity)
	if (!fMouseTracking && (fPageAngle > kPageMinAngle) && (fPageAngle < kPageMaxAngle))
	{
		if (fPageAngle < 90)
			fPageAngle -= 30*(float)delta/1000000.0f;
		else
			fPageAngle += 30*(float)delta/1000000.0f;
	}
	fPages[PAGE_MIDDLE]->SetAngle(fPageAngle);
	
	//	Draw pages
	glPushMatrix();
	glTranslatef(-0.5f*kPageWidth, 0.5f*kPageHeight, 0);
	fPages[PAGE_MIDDLE]->Render();
	glPopMatrix();
	
	glPushMatrix();
	glTranslatef(-0.5f*kPageWidth, 0.5f*kPageHeight, 0);
	fPages[PAGE_LEFT]->Render();
	glPopMatrix();
	
	glPushMatrix();
	glTranslatef(-0.5f*kPageWidth, 0.5f*kPageHeight, 0);
	fPages[PAGE_RIGHT]->Render();
	glPopMatrix();
	
	
	glFlush();
	SwapBuffers();
	
	//	Frame rate
	/*
	static int fps = 0;
	static int time_delta = 0;
	fps++;
	time_delta += delta;
	if (time_delta > 1000000)
	{
		printf("%d fps\n", fps);
		fps = 0;
		time_delta = 0;
	}
	*/
	UnlockGL();
}
示例#13
0
void TutGLView::FrameResized( float width, float height )
{
	// When the view is resized (it follows the window, since we created
	// it with B_FOLLOW_ALL_SIDES), we need to tell OpenGL that it's
	// rendering into a new size/shape.
	LockGL();
	BGLView::FrameResized( width, height );
	gReshape( width, height );
	UnlockGL();
	Render();
}
示例#14
0
/*	FUNCTION:		ViewObject :: Render
	ARGUMENTS:		none
	RETURN:			n/a
	DESCRIPTION:	Should be overriden by derived class	
*/
void ViewObject :: Render(void)
{
	LockGL();
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	// derived class should draw something here
	
	glFlush();
	SwapBuffers();
	UnlockGL();
}
示例#15
0
void TutGLView::Render( void )
{
	// Render our OpenGL scene and swap the buffer so we can actually see
	// it.
	LockGL();
	gDraw();
	if( _window->draw_mutex->Lock() ) {
		if( _window->window_connected ) SwapBuffers();
		_window->draw_mutex->Unlock();
	}
	UnlockGL();
}
示例#16
0
void SampleGLView::FrameResized(float newWidth, float newHeight)
{
    BGLView::FrameResized(newWidth, newHeight);

    LockGL();

    width = newWidth;
    height = newHeight;

    gReshape(width,height);

    UnlockGL();
    Render();
}
示例#17
0
void
BGLView::FrameResized(float width, float height)
{
	fBounds = Bounds();
	for (BView *v = this; v; v = v->Parent())
		v->ConvertToParent(&fBounds);

	if (fRenderer) {
		LockGL();
		_LockDraw();
		fRenderer->FrameResized(width, height);
		_UnlockDraw();
		UnlockGL();
	}

   	BView::FrameResized(width, height);
}
示例#18
0
/*	FUNCTION:		ViewCube :: ViewCube
	ARGUMENTS:		none
	RETURN:			n/a
	DESCRIPTION:	Hook function called when view attached to window (looper)
*/
void ViewCube :: AttachedToWindow(void)
{
	ViewObject::AttachedToWindow();
	
	LockGL();
	glClearColor(0,0,0,1);
	
	fCube = new Cube(0.075f);
	
	for (int i=0; i < NUMBER_FACES; i++)
	{
		fMediaSources[i] = GetDefaultMediaSource();
		fCube->SetMediaSource((Cube::FACE) i, fMediaSources[i]);
	}
	
	UnlockGL();
}	
示例#19
0
void TutGLView::AttachedToWindow( void )
{
	// Make keyboard/mouse input go to this view when its window has
	// focus (that'll stay in effect until another view calls MakeFocus()
	// or the user puts the focus on a control... which won't happen in
	// this app because there are no other views and no controls).
	MakeFocus();

	// Initialize OpenGL; gInit() sets things up, gReshape() makes sure
	// OpenGL knows about the view's size/shape.
	LockGL();
	BGLView::AttachedToWindow();
	gInit();
	BRect r = Bounds();
	gReshape( r.IntegerWidth(), r.IntegerHeight() );
	UnlockGL();
}
示例#20
0
/*	FUNCTION:		ViewObject :: AttachedToWindow
	ARGUMENTS:		none
	RETURN:			n/a
	DESCRIPTION:	Hook function called when view attached to window (looper)
*/
void ViewObject :: AttachedToWindow(void)
{
	LockGL();
	BGLView::AttachedToWindow();
	
	//	init OpenGL state
	glClearColor(0, 0, 0, 1);
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_TEXTURE_2D);
	glDepthFunc(GL_LESS);
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	
	//	init default texture (drag and drop media files)
	if (sDefaultMediaSource == 0)
	{		
		sDefaultImage = BTranslationUtils::GetBitmap(B_PNG_FORMAT, "instructions.png");

		sDefaultMediaSource = new MediaSource(this);
		glGenTextures(1, &sDefaultMediaSource->mTextureID);
		glBindTexture(GL_TEXTURE_2D, sDefaultMediaSource->mTextureID);
	
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
		int num_bytes;
		GLDetermineFormat(sDefaultImage->ColorSpace(), &sDefaultMediaSource->mTextureFormat, &num_bytes);
		glTexImage2D(GL_TEXTURE_2D,
				0, 										// mipmap level
				num_bytes,								// internal format
				sDefaultImage->Bounds().IntegerWidth() + 1,					// width
				sDefaultImage->Bounds().IntegerHeight() + 1,				// height
				0,										// border
				sDefaultMediaSource->mTextureFormat,	// format of pixel data
				GL_UNSIGNED_BYTE,						// data type
				(unsigned char *) sDefaultImage->Bits());		// pixels
	}
		
	MakeFocus(true);
	UnlockGL();
}	
示例#21
0
/*	FUNCTION:		ViewObject :: FrameResized
	ARGUMENTS:		width
					height
	RETURN:			n/a
	DESCRIPTION:	Hook function called when view resized.
					Since we have a static camera, we configure it here.
					If we had a dynamic camera, then we'd have to reposition
					the camera in the derived view.	
*/
void ViewObject :: FrameResized(float width, float height)
{
	LockGL();
	BGLView::FrameResized(width, height);
	glViewport(0, 0, (int)width, (int)height);
	
	//	Camera projection
	glMatrixMode(GL_PROJECTION);
	float m[16];
	GLCreatePerspectiveMatrix(m, 30, width/height, 0.1f, 10);
	glLoadMatrixf(m);
	
	//	Camera position
	glMatrixMode(GL_MODELVIEW);
	GLCreateModelViewMatrix(m, 0, -0.45f, 0.4f, 0, -30);
	glLoadMatrixf(m);
	
	UnlockGL();
}
示例#22
0
void CMassView::AttachedToWindow()													//	called when added to window
{
	GLfloat light_position[] = {0.0, 3.0, 4.0, 0.0};								// position of light source (at infinity)			
	GLfloat light_colour[] = {1.0, 1.0, 1.0, 0.0};									//	colour of light source

	GLfloat torus_colour[] = {1.0, 1.0, 1.0, 0.0};									// set the torus to green								
//	GLfloat torus_specular_colour[] = {1.0, 1.0, 1.0, 0.0};							// and set shininess up a little bit
	BGLView::AttachedToWindow();													//	call inherited attachment function
	LockGL();																		//	make sure this is thread-safe

	glMatrixMode(GL_PROJECTION);													//	first set up matrix for the viewing volume	
	glOrtho(-240.0, 240.0, -200.0, 200.0, -1000.0, 1000.0);							//	set the perspective									
 	glMatrixMode(GL_MODELVIEW);														// switch to matrix for basis vectors at eye		
	glLoadIdentity();																//	load the identity matrix
	glTranslatef(0, 0, -600.0);														//	translate the model matrix									
//	glRotatef(30.0, 0.0, 1.0, 0.0);													//	rotate the torus
	torusPickListID = glGenLists(2);												//	set up a total of 1 display list					
	glNewList(torusPickListID, GL_COMPILE);											//	tell it to save the following calls			
	CreateTorus(100.0, 50.0, GL_SELECT);											//	set up a list for rendering
	glEndList();																	// close the list											
	glShadeModel(GL_SMOOTH);														// use smooth lighting										
	glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, torus_colour);					// set the colour of the torus						
	glLightfv(GL_LIGHT0, GL_POSITION, light_position);								// specify the position of the light				
	glLightfv(GL_LIGHT0, GL_DIFFUSE, light_colour);									//	and the colour
	glEnable(GL_LIGHTING);															// switch lighting on									
	glEnable(GL_LIGHT0);															// switch light #0 on									
	glEnable(GL_DEPTH_TEST);														//	make sure depth buffer is switched on			
	glEnable(GL_TEXTURE_2D);														//	enable 2D textures
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);											//	set the pixel alignment
	glGenTextures(1, &texName);														//	create the GL texture "name"
	glBindTexture(GL_TEXTURE_2D, texName);											//	mark it as 2D
	
	torusDisplayListID = torusPickListID + 1;										//	we know this name is available
	glNewList(torusDisplayListID, GL_COMPILE);										//	tell it to save the following calls				
	CreateTorus(100.0, 50.0, GL_RENDER);											//	set up a list for rendering
	glEndList();																	// close the list											
	UnlockGL();																		//	unlock GL

	FrameResized(Bounds().Width(), Bounds().Height());
	
} // end of AttachedToWindow()
示例#23
0
/*	FUNCTION:		ViewObject :: GLCheckError
	ARGUMENTS:		none
	RETURN:			n/a
	DESCRIPTION:	Check for OpenGL errors
*/
void ViewObject :: GLCheckError()
{
	GLenum err;
	
	LockGL();
	while ((err = glGetError()) != GL_NO_ERROR)
	{
		printf("[GL Error]  ");
		switch (err)
		{
			case GL_INVALID_ENUM:		printf("GL_INVALID_ENUM\n");		break;
			case GL_INVALID_VALUE:		printf("GL_INVALID_VALUE\n");		break;
			case GL_INVALID_OPERATION:	printf("GL_INVALID_OPERATION\n");	break;
			case GL_STACK_OVERFLOW:		printf("GL_STACK_OVERFLOW\n");		break;
			case GL_STACK_UNDERFLOW:	printf("GL_STACK_UNDERFLOW\n");		break;
			case GL_OUT_OF_MEMORY:		printf("GL_OUT_OF_MEMORY\n");		break;
			default:					printf("%d\n", err);				break;
		}
	}
	UnlockGL();
}
示例#24
0
void
ObjectView::FrameResized(float width, float height)
{
	LockGL();

	BGLView::FrameResized(width, height);

	width = Bounds().Width();
	height = Bounds().Height();
	fYxRatio = height / width;
    glViewport(0, 0, (GLint)width + 1, (GLint)height + 1);

	// To prevent weird buffer contents
	glClear(GL_COLOR_BUFFER_BIT);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	float scale = displayScale;

	if (fPersp) {
		gluPerspective(60, 1.0 / fYxRatio, 0.15, 120);
	} else {
		if (fYxRatio < 1) {
			glOrtho(-scale / fYxRatio, scale / fYxRatio, -scale, scale, -1.0,
				depthOfView * 4);
		} else {
			glOrtho(-scale, scale, -scale * fYxRatio, scale * fYxRatio, -1.0,
				depthOfView * 4);
		}
	}

	fLastYXRatio = fYxRatio;

	glMatrixMode(GL_MODELVIEW);

	UnlockGL();

	fForceRedraw = true;
	setEvent(drawEvent);
}
示例#25
0
void learnView::Display()
{
#if 0
	spinDisplay();
//	xrotate = 45;
	LockGL();
//	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glClear ( GL_COLOR_BUFFER_BIT );
	glColor3f(1.0, 1.0, 1.0);
	glLoadIdentity();
	gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
	glScalef(1.0, 1.0, 1.0);
	glRotatef(xrotate, 1, 0, 0);
	glRotatef(yrotate, 0, 1, 0);
	DrawFrame();
	glFlush();

	//printf("calling swap buffers...\n");
	SwapBuffers();
	
	UnlockGL();
#endif
}
示例#26
0
bool
ObjectView::RepositionView()
{
	if (!(fPersp != fLastPersp) &&
		!(fLastObjectDistance != fObjectDistance) &&
		!(fLastYXRatio != fYxRatio)) {
		return false;
	}

	LockGL();

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	float scale = displayScale;

	if (fPersp) {
		gluPerspective(60, 1.0 / fYxRatio, 0.15, 120);
	} else {
		if (fYxRatio < 1) {
			glOrtho(-scale / fYxRatio, scale / fYxRatio, -scale, scale, -1.0,
				depthOfView * 4);
		} else {
			glOrtho(-scale, scale, -scale * fYxRatio, scale * fYxRatio, -1.0,
				depthOfView * 4);
		}
	}

	glMatrixMode(GL_MODELVIEW);

	UnlockGL();

	fLastObjectDistance = fObjectDistance;
	fLastPersp = fPersp;
	fLastYXRatio = fYxRatio;
	return true;
}
示例#27
0
/*	FUNCTION:		ViewCube :: Render
	ARGUMENTS:		none
	RETURN:			n/a
	DESCRIPTION:	Draw view contents	
*/
void ViewCube :: Render(void)
{
	LockGL();
	
	bigtime_t	current_time = real_time_clock_usecs();
	bigtime_t	delta = current_time - fStartTime;
	fStartTime = current_time;		
		
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	fCubeAngle += fSpeed*(float)delta/1000000.0f;
	fCube->SetAngle(0, 0, fCubeAngle);
	
	glPushMatrix();
	glTranslatef(0.0f, 0.0f, 0.15f);
	fCube->Render();
	glPopMatrix();
		
	glFlush();
	SwapBuffers();
	
	//	Display frame rate
	/*
	static int fps = 0;
	static int time_delta = 0;
	fps++;
	time_delta += delta;
	if (time_delta > 1000000)
	{
		printf("%d fps\n", fps);
		fps = 0;
		time_delta = 0;
	}
	*/
	UnlockGL();
}
示例#28
0
bool
ObjectView::SpinIt()
{
	bool changed = false;

	if (fGouraud != fLastGouraud) {
		LockGL();
		glShadeModel(fGouraud ? GL_SMOOTH : GL_FLAT);
		UnlockGL();
		fLastGouraud = fGouraud;
		changed = true;
	}

	if (fZbuf != fLastZbuf) {
		LockGL();
		if (fZbuf)
			glEnable(GL_DEPTH_TEST);
		else
			glDisable(GL_DEPTH_TEST);
		UnlockGL();
		fLastZbuf = fZbuf;
		changed = true;
	}

	if (fCulling != fLastCulling) {
		LockGL();
		if (fCulling)
			glEnable(GL_CULL_FACE);
		else
			glDisable(GL_CULL_FACE);
		UnlockGL();
		fLastCulling = fCulling;
		changed = true;
	}

	if (fLighting != fLastLighting) {
		LockGL();
		if (fLighting)
			glEnable(GL_LIGHTING);
		else
			glDisable(GL_LIGHTING);
		UnlockGL();
		fLastLighting = fLighting;
		changed = true;
	}

	if (fFilled != fLastFilled) {
		LockGL();
		if (fFilled) {
			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
		} else {
			glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
		}
		UnlockGL();
		fLastFilled = fFilled;
		changed = true;
	}

	if (fFog != fLastFog) {
		if (fFog) {
			glFogf(GL_FOG_START, 1.0);
			glFogf(GL_FOG_DENSITY, 0.2);
			glFogf(GL_FOG_END, depthOfView);
			glFogfv(GL_FOG_COLOR, foggy);
			glEnable(GL_FOG);
			bgColor = foggy;
			glClearColor(bgColor[0], bgColor[1], bgColor[2], 1.0);
		} else {
			glDisable(GL_FOG);
			bgColor = black;
			glClearColor(bgColor[0], bgColor[1], bgColor[2], 1.0);
		}
		fLastFog = fFog;
		changed = true;
	}

	changed = changed || RepositionView();
	changed = changed || fForceRedraw;
	fForceRedraw = false;

	for (int i = 0; i < fObjects.CountItems(); i++) {
		bool hack = reinterpret_cast<GLObject*>(fObjects.ItemAt(i))->SpinIt();
		changed = changed || hack;
	}

	return changed;
}
示例#29
0
void
ObjectView::DrawFrame(bool noPause)
{
	LockGL();
	glClear(GL_COLOR_BUFFER_BIT | (fZbuf ? GL_DEPTH_BUFFER_BIT : 0));

	fObjListLock.Lock();
	for (int i = 0; i < fObjects.CountItems(); i++) {
	  GLObject *object = reinterpret_cast<GLObject*>(fObjects.ItemAt(i));
		if (object->Solidity() == 0)
			object->Draw(false, NULL);
	}
	EnforceState();
	for (int i = 0; i < fObjects.CountItems(); i++) {
		GLObject *object = reinterpret_cast<GLObject*>(fObjects.ItemAt(i));
		if (object->Solidity() != 0)
			object->Draw(false, NULL);
	}
	fObjListLock.Unlock();

	glDisable(GL_BLEND);
	glDepthMask(GL_TRUE);

	if (noPause) {
		uint64 now = system_time();
		float fps = 1.0 / ((now - fLastFrame) / 1000000.0);
		fLastFrame = now;
		int entry;
		if (fHistEntries < HISTSIZE) {
			entry = (fOldestEntry + fHistEntries) % HISTSIZE;
			fHistEntries++;
		} else {
			entry = fOldestEntry;
			fOldestEntry = (fOldestEntry + 1) % HISTSIZE;
		}

		fFpsHistory[entry] = fps;

		if (fHistEntries > 5) {
			fps = 0;
			for (int i = 0; i < fHistEntries; i++)
				fps += fFpsHistory[(fOldestEntry + i) % HISTSIZE];

			fps /= fHistEntries;

			if (fFps) {
				glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING_BIT);
				glPushMatrix();
				glLoadIdentity();
				glTranslatef(-0.9, -0.9, 0);
				glScalef(0.10, 0.10, 0.10);
				glDisable(GL_LIGHTING);
				glDisable(GL_DEPTH_TEST);
				glDisable(GL_BLEND);
				glColor3f(1.0, 1.0, 0);
				glMatrixMode(GL_PROJECTION);
				glPushMatrix();
				glLoadIdentity();
				glMatrixMode(GL_MODELVIEW);

				FPS::drawCounter(fps);

				glMatrixMode(GL_PROJECTION);
				glPopMatrix();
				glMatrixMode(GL_MODELVIEW);
				glPopMatrix();
				glPopAttrib();
			}
		}
	} else {
		fHistEntries = 0;
		fOldestEntry = 0;
	}
	SwapBuffers();
	UnlockGL();
}
示例#30
0
void CMassView::MouseDown(BPoint where)												//	reacts to mouse clicks
	{
	long whichButtons = 1;															//	used for tracking which buttons are down
	Window()->CurrentMessage()->FindInt32("buttons", &whichButtons);				//	find out which buttons are down
	
	if (inGLMode && (whichButtons & B_SECONDARY_MOUSE_BUTTON))						//	if we are in GL mode, and button 2 is down
		{
		float frameWidth = Frame().Width(), frameHeight = Frame().Height();			//	find the width & height
		dragMode = dragBall;														//	drag the arcball to rotate									
		HVect vNow;																	//	vector type for passing to ball functions					
		vNow.x = (2.0 * where.x - frameWidth)/frameWidth;							//	set the vector										
		vNow.y = -(2.0 * where.y - frameHeight)/frameHeight;							//	in both dimensions									
		Ball_Mouse(&ball, vNow);													//	and pass it to the Ball functions							
		Ball_BeginDrag(&ball);														//	start dragging										
		while (whichButtons)														//	loop until drop the mouse
			{
			snooze(20 * 1000);														//	snooze for 20 µs
			GetMouse(&where, (ulong *)&whichButtons, true);									//	get the mouse location, &c.
			vNow.x = (2.0 * where.x - frameWidth)/frameWidth;						//	set the vector	
			vNow.y = -(2.0 * where.y - frameHeight)/frameHeight;						//	in both dimensions
			Ball_Mouse(&ball, vNow);												//	and pass it to the Ball functions
			Draw(Frame());															//	redraw the entire frame
			} // end of while (whichButtons)
		Ball_EndDrag(&ball);														//	stop dragging	
		} // end of case where dragging

	else if (acceptClicks)															//	if we have "accept" switched on
		{
		long row, col;																//	the board coordinates of the click
		if (!inGLMode)																//	if it's the regular board
			{
			row = where.y / CELL_SIZE;												//	calculate which row to look in
			col = where.x / CELL_SIZE;												//	and which column
			} // end of normal mode
		else 
			{
			GLubyte theColour[4];													//	array for retrieving "colour"
			LockGL();																//	lock in preparation for drawing
			GLfloat mNow[16];														//	local matrix for ball routines							
			Ball_Update(&ball);														//	update the data for the ball								
			Ball_Value(&ball, mNow);												//	retrieve the ball's position as a matrix						
			glDisable(GL_LIGHTING);													//	disable lighting
			glShadeModel(GL_FLAT);													//	switch to flat shading
			glMatrixMode(GL_MODELVIEW);												//	make sure that we are set to the model matrix				
			glClearColor(0.0, 0.0, 0.0, 1.0);										//	and set the "clear" colour to black						
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);						//	clear the window to black								
			glPushMatrix();															//	push the GL stack to get a new matrix						
			glLoadIdentity();														//	load the identity matrix								
			glTranslatef(0, 0, -600.0);												//	translate the model matrix									
			glMultMatrixf(mNow);													//	multiply by this matrix								
			glCallList(torusPickListID);											// and call the display list							
			glReadPixels(where.x, Frame().Height() - where.y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, theColour);
																					//	read a single pixel at the mouse location
			glPopMatrix();															//	pop the matrix back off the stack
			glEnable(GL_LIGHTING);													//	re-enable lighting
			glShadeModel(GL_SMOOTH);												//	and smoothness
			UnlockGL();																//	unlock GL
			Draw(Frame());															//	redraw the entire picture
			row = theColour[1] - 128; col = theColour[0] - 128;						//	retrieve the row & column
																					//	(background is black & returns -128)
//			printf("%d %d\n", row, col); return;
			} // end of GL mode code
		if (row < 0) return;														//	make sure it is a legal cell
		else if (row >= theBoard.getHeight()) return;										//	i.e. not off top or bottom
		if (col < 0) return;														//	same with left & right
		else if (col >= theBoard.getWidth()) return;	
		
		BMessage *theMessage = new BMessage(CM_MSG_MOVE_CHOSEN);					//	create a message for it
		acceptClicks = false;														//	turn off "accept clicks"
		theMessage->AddInt32("row", row); theMessage->AddInt32("column", col);		//	add the coordinates to the message
		be_app->PostMessage(theMessage);											//	send the message off
		delete theMessage;															//	get rid of the message when done
		} // end of case where we accept clicks
	} // end of MouseDown()