void RenderManagerGL2D::draw()
{
	glClear(GL_DEPTH_BUFFER_BIT);
	if (!mDrawGame)
		return;
		
	// Background
	glDisable(GL_ALPHA_TEST);
	glColor4f(1.0, 1.0, 1.0, 1.0);
	glBindTexture(mBackground);
	glLoadIdentity();
	drawQuad2(400.0, 300.0, 1024.0, 1024.0);
	
	
	if(mShowShadow)
	{
		// Generic shadow settings
		
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glEnable(GL_BLEND);

		// Blob shadows
		Vector2 pos;
	
		pos = blobShadowPosition(mLeftBlobPosition);
		glColor4ub(mLeftBlobColor.r, mLeftBlobColor.g, mLeftBlobColor.b, 128);
		glBindTexture(mBlobShadow[int(mLeftBlobAnimationState)  % 5]);
		drawQuad2(pos.x, pos.y, 128.0, 32.0);
	
		pos = blobShadowPosition(mRightBlobPosition);
		glColor4ub(mRightBlobColor.r, mRightBlobColor.g, mRightBlobColor.b, 128);
		glBindTexture(mBlobShadow[int(mRightBlobAnimationState)  % 5]);
		drawQuad2(pos.x, pos.y, 128.0, 32.0);

		// Ball shadow	
		pos = ballShadowPosition(mBallPosition);
		glColor4f(1.0, 1.0, 1.0, 0.5);
		glBindTexture(mBallShadow);
		drawQuad2(pos.x, pos.y, 128.0, 32.0);

		glDisable(GL_BLEND);
	}
	
	glEnable(GL_ALPHA_TEST);
		
	// General object settings
	glBlendFunc(GL_SRC_ALPHA, GL_ONE);
	// The Ball
	
	glColor4f(1.0, 1.0, 1.0, 1.0);
	glBindTexture(mBall[int(mBallRotation / M_PI / 2 * 16) % 16]);
/*
	float opacity = 0.0;
	for (std::list<Vector2>::iterator iter = mLastBallStates.begin();
		iter != mLastBallStates.end(); ++iter)
	{
//		glColor4f(1.0 / MotionBlurIterations, 
//			1.0 / MotionBlurIterations, 1.0 / MotionBlurIterations, 1.0 - opacity);
		glColor4f(1.0, 1.0, 1.0, opacity);
		
		
		Vector2& ballPosition = *iter;
*/
		drawQuad2(mBallPosition.x, mBallPosition.y, 64.0, 64.0);

/*
		opacity += 0.1;
	}
	if (mLastBallStates.size() > MotionBlurIterations)
			mLastBallStates.pop_back();
	glDisable(GL_BLEND);
*/	
	
	// blob normal
	// left blob
	glBindTexture(mBlob[int(mLeftBlobAnimationState)  % 5]);
	glColor3ubv(mLeftBlobColor.val);
	drawQuad2(mLeftBlobPosition.x, mLeftBlobPosition.y, 128.0, 128.0);
	
	// right blob
	glBindTexture(mBlob[int(mRightBlobAnimationState)  % 5]);
	glColor3ubv(mRightBlobColor.val);
	drawQuad2(mRightBlobPosition.x, mRightBlobPosition.y, 128.0, 128.0);

	// blob specular
	glEnable(GL_BLEND);
	glColor4f(1.0, 1.0, 1.0, 1.0);
	// left blob
	glBindTexture(mBlobSpecular[int(mLeftBlobAnimationState)  % 5]);
	drawQuad2(mLeftBlobPosition.x, mLeftBlobPosition.y, 128.0, 128.0);

	// right blob
	glBindTexture(mBlobSpecular[int(mRightBlobAnimationState)  % 5]);
	drawQuad2(mRightBlobPosition.x, mRightBlobPosition.y, 128.0, 128.0);
	
	glDisable(GL_BLEND);
	

	// Ball marker
	glDisable(GL_ALPHA_TEST);
	glDisable(GL_TEXTURE_2D);
	GLubyte markerColor = SDL_GetTicks() % 1000 >= 500 ? 255 : 0;
	glColor3ub(markerColor, markerColor, markerColor);
	drawQuad2(mBallPosition.x, 7.5, 5.0, 5.0);

	// Mouse marker

	// Position relativ zu BallMarker
	drawQuad2(mMouseMarkerPosition, 592.5, 5.0, 5.0);
	
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_ALPHA_TEST);
	
	// Scores
	char textBuffer[64];
	snprintf(textBuffer, 8, mLeftPlayerWarning ? "%02d!" : "%02d",
			mLeftPlayerScore);
	drawText(textBuffer, Vector2(24, 24), false);
	snprintf(textBuffer, 8, mRightPlayerWarning ? "%02d!" : "%02d",
			mRightPlayerScore);	
	drawText(textBuffer, Vector2(728, 24), false);

	// Drawing the names
	drawText(mLeftPlayerName, Vector2(12, 550), false);

	drawText(mRightPlayerName, Vector2(788-(24*mRightPlayerName.length()), 550), false);
	
	// Drawing the clock
	drawText(mTime, Vector2(400 - mTime.length()*12, 24), false);
}
예제 #2
0
void RenderManagerGL2D::draw()
{
	if (!mDrawGame)
		return;

	// Background
	glDisable(GL_ALPHA_TEST);
	glColor4f(1.0, 1.0, 1.0, 1.0);
	glBindTexture(mBackground);
	glLoadIdentity();
	drawQuad(400.0, 300.0, 1024.0, 1024.0);


	if(mShowShadow)
	{
		// Generic shadow settings

		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glEnable(GL_BLEND);

		// Blob shadows
		Vector2 pos;

		pos = blobShadowPosition(mLeftBlobPosition);
		glColor4ub(mLeftBlobColor.r, mLeftBlobColor.g, mLeftBlobColor.b, 128);
		glBindTexture(mBlobShadow[int(mLeftBlobAnimationState)  % 5]);
		drawQuad(pos.x, pos.y, 128.0, 32.0);

		pos = blobShadowPosition(mRightBlobPosition);
		glColor4ub(mRightBlobColor.r, mRightBlobColor.g, mRightBlobColor.b, 128);
		glBindTexture(mBlobShadow[int(mRightBlobAnimationState)  % 5]);
		drawQuad(pos.x, pos.y, 128.0, 32.0);

		// Ball shadow
		pos = ballShadowPosition(mBallPosition);
		glColor4f(1.0, 1.0, 1.0, 0.5);
		glBindTexture(mBallShadow);
		drawQuad(pos.x, pos.y, 128.0, 32.0);

		glDisable(GL_BLEND);
	}

	glEnable(GL_ALPHA_TEST);

	// General object settings
	glBlendFunc(GL_SRC_ALPHA, GL_ONE);
	// The Ball

	glColor4f(1.0, 1.0, 1.0, 1.0);
	glBindTexture(mBall[int(mBallRotation / M_PI / 2 * 16) % 16]);
/*
	float opacity = 0.0;
	for (std::list<Vector2>::iterator iter = mLastBallStates.begin();
		iter != mLastBallStates.end(); ++iter)
	{
//		glColor4f(1.0 / MotionBlurIterations,
//			1.0 / MotionBlurIterations, 1.0 / MotionBlurIterations, 1.0 - opacity);
		glColor4f(1.0, 1.0, 1.0, opacity);


		Vector2& ballPosition = *iter;
*/
		drawQuad(mBallPosition.x, mBallPosition.y, 64.0, 64.0);

/*
		opacity += 0.1;
	}
	if (mLastBallStates.size() > MotionBlurIterations)
			mLastBallStates.pop_back();
	glDisable(GL_BLEND);
*/

	// blob normal
	// left blob
	glBindTexture(mBlob[int(mLeftBlobAnimationState)  % 5]);
	glColor3ubv(mLeftBlobColor.val);
	drawQuad(mLeftBlobPosition.x, mLeftBlobPosition.y, 128.0, 128.0);

	// right blob
	glBindTexture(mBlob[int(mRightBlobAnimationState)  % 5]);
	glColor3ubv(mRightBlobColor.val);
	drawQuad(mRightBlobPosition.x, mRightBlobPosition.y, 128.0, 128.0);

	// blob specular
	glEnable(GL_BLEND);
	glColor4f(1.0, 1.0, 1.0, 1.0);
	// left blob
	glBindTexture(mBlobSpecular[int(mLeftBlobAnimationState)  % 5]);
	drawQuad(mLeftBlobPosition.x, mLeftBlobPosition.y, 128.0, 128.0);

	// right blob
	glBindTexture(mBlobSpecular[int(mRightBlobAnimationState)  % 5]);
	drawQuad(mRightBlobPosition.x, mRightBlobPosition.y, 128.0, 128.0);

	glDisable(GL_BLEND);


	// Ball marker
	glDisable(GL_ALPHA_TEST);
	glDisable(GL_TEXTURE_2D);
	GLubyte markerColor = SDL_GetTicks() % 1000 >= 500 ? 255 : 0;
	glColor3ub(markerColor, markerColor, markerColor);
	drawQuad(mBallPosition.x, 7.5, 5.0, 5.0);

	// Mouse marker

	// Position relativ zu BallMarker
	drawQuad(mMouseMarkerPosition, 592.5, 5.0, 5.0);

	glEnable(GL_TEXTURE_2D);
	glEnable(GL_ALPHA_TEST);
}
예제 #3
0
void RenderManagerSDL::draw()
{
    if (!mDrawGame)
        return;

    SDL_RenderCopy(mRenderer,
                   mBackground,
                   NULL,
                   NULL);

    int animationState;
    SDL_Rect position;

    // Ball marker
    position.y = 5;
    position.x = (int)lround(mBallPosition.x - 2.5);
    position.w = 5;
    position.h = 5;
    SDL_RenderCopy(mRenderer, mMarker[(int)SDL_GetTicks() % 1000 >= 500], 0, &position);

    // Mouse marker
    position.y = 590;
    position.x = (int)lround(mMouseMarkerPosition - 2.5);
    position.w = 5;
    position.h = 5;
    SDL_RenderCopy(mRenderer, mMarker[(int)SDL_GetTicks() % 1000 >= 500], 0, &position);

    if(mShowShadow)
    {
        // Ball Shadow
        position = ballShadowRect(ballShadowPosition(mBallPosition));
        SDL_RenderCopy(mRenderer, mBallShadow, 0, &position);

        // Left blob shadow
        position = blobShadowRect(blobShadowPosition(mLeftBlobPosition));
        animationState = int(mLeftBlobAnimationState) % 5;
        SDL_RenderCopy(mRenderer, mLeftBlobShadow[animationState].mSDLsf, 0, &position);

        // Right blob shadow
        position = blobShadowRect(blobShadowPosition(mRightBlobPosition));
        animationState = int(mRightBlobAnimationState) % 5;
        SDL_RenderCopy(mRenderer, mRightBlobShadow[animationState].mSDLsf, 0, &position);
    }

    // Restore the rod
    position.x = 400 - 7;
    position.y = 300;
    SDL_Rect rodPosition;
    rodPosition.x = 400 - 7;
    rodPosition.y = 300;
    rodPosition.w = 14;
    rodPosition.h = 300;
    SDL_RenderCopy(mRenderer, mBackground, &rodPosition, &rodPosition);

#ifdef __APPLE__
#if !MAC_OS_X
    position.x = 400 - 35;
    position.y = 70;
    position.w = 70;
    position.h = 82;
    SDL_RenderCopy(mRenderer, mBackFlag, 0, &position);
#endif
#endif

    // Drawing the Ball
    position = ballRect(mBallPosition);
    animationState = int(mBallRotation / M_PI / 2 * 16) % 16;
    SDL_RenderCopy(mRenderer, mBall[animationState], 0, &position);

    // update blob colors
    colorizeBlobs(LEFT_PLAYER);
    colorizeBlobs(RIGHT_PLAYER);

    // Drawing left blob
    position = blobRect(mLeftBlobPosition);
    animationState = int(mLeftBlobAnimationState) % 5;
    SDL_RenderCopy(mRenderer, mLeftBlob[animationState].mSDLsf, 0, &position);

    // Drawing right blob
    position = blobRect(mRightBlobPosition);
    animationState = int(mRightBlobAnimationState) % 5;
    SDL_RenderCopy(mRenderer, mRightBlob[animationState].mSDLsf, 0, &position);
}