1

I am creating a 3D game. I have objects in my game. When an enemy hits my position I want my screen to go red for a short time. I have chosen to do this by trying to render a full screen red square at my camera position. This is my attempt which is in my render method.

     RenderQuadTerrain();   

    //Draw the skybox
    CreateSkyBox(vNewPos.x,  vNewPos.y,  vNewPos.z,3500,3000,3500);
    DrawCoins();

    CollisionTest(g_Camera.Position().x, g_Camera.Position().y, g_Camera.Position().z);
    DrawEnemy();
    DrawEnemy1();

    //Draw SecondaryObjects models
    DrawSecondaryObjects(); 

    //Apply lighting effects
    LightingEffects();
    escapeAttempt();
if(hitbyenemy==true){
    glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE); // additive blending
float blendFactor = 1.0;
glColor3f(blendFactor ,0,0); // when blendFactor = 0, the quad won't be visible. When    blendFactor=1, the scene will be bathed in redness

    glBegin(GL_QUADS);                      // Draw A Quad
    glVertex3f(-1.0f, 1.0f, 0.0f);              // Top Left
    glVertex3f( 1.0f, 1.0f, 0.0f);              // Top Right
    glVertex3f( 1.0f,-1.0f, 0.0f);              // Bottom Right
    glVertex3f(-1.0f,-1.0f, 0.0f);              // Bottom Left
glEnd();
}

All this does, however, is turn all of the objects in my game a transparent colour, and I can't see the square anywhere. I don't even know how to position the quad. I'm very new to openGL.

How my game looks without an attempt to render a quad: enter image description here

How my game looks after my attempt: enter image description here

With Kevin's code and glDisable(GL_DEPTH_TEST); enter image description here

EDIT: I have changed the code to the below paste..still looks like image 1.

http://pastebin.com/eiVFcQqM

4

1 回答 1

2

这个问题有几个可能的贡献:

  • 您可能需要定期混合,而不是添加剂混合;加法混合不会将白色、黄色或紫色物体变为红色。将混合函数更改为glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);并使用颜色glColor4f(1, 0, 0, blendFactor);

  • 您应该glDisable(GL_DEPTH_TEST);在绘制叠加层时防止它被其他几何体隐藏,然后重新启用它(或使用glPush/PopAttrib(GL_ENABLE_BIT))。

  • 投影和模型视图矩阵应该是恒等的,以确保具有这些坐标的四边形覆盖整个屏幕。(但是,您可能已经隐含了,因为您说它正在影响全屏,只是方式不正确。)

如果这些建议不能解决问题,请编辑您的问题,显示带有和不带有红色闪光的游戏截图,以便我们更好地理解问题。

于 2012-07-30T23:57:18.430 回答