Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


How to draw a full screen quad and still see the objects behind it


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 gurps   Members   -  Reputation: 105

Like
0Likes
Like

Posted 31 July 2012 - 11:24 AM

http://pastebin.com/9UAD5Vpr

I want to create an effect where when my player is hit by an enemy...the screen goes red to indicate the player has taken damage and then after a few seconds begins to fade away.

My attempt is shown in the pastebin link above however it doesn't work. No red is rendered although my game objects, terrain and models appear.

I will appreciate any help and advice to solve this problem.

Thank you Posted Image

Edited by gurps, 01 August 2012 - 01:22 PM.


Sponsor:

#2 Neometron   Members   -  Reputation: 435

Like
0Likes
Like

Posted 31 July 2012 - 12:32 PM

glColor4f(1, 0, 0, blendFactor); //blendFactor = 1

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

If you move your camera around to this location, do you see a red quad being drawn?
If so, you should look into billboarding the quad to a set distance from the camera.

#3 gurps   Members   -  Reputation: 105

Like
0Likes
Like

Posted 31 July 2012 - 12:56 PM

Thanks for the reply..but no red quad being drawn.

[source lang="cpp"]void RenderScene() { // Give OpenGL our camera position glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glLoadIdentity(); g_Camera.Look(); CVector3 vPos = g_Camera.Position(); CVector3 vNewPos = vPos; CVector3 vView = g_Camera.View(); if (introScreen == true) { GLTexture tex; tex.Load("Intro.bmp"); tex.Use(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(-1.0f, -1.0f, -1.5f); glTexCoord2f(1.0, 0.0); glVertex3f(1.0f, -1.0f, -1.5f); glTexCoord2f(1.0, 1.0); glVertex3f(1.0f, 1.0f, -1.5f); glTexCoord2f(0.0, 1.0); glVertex3f(-1.0f, 1.0f, -1.5f); glEnd(); glPopMatrix(); //If we are on an introscreen, we can render it here, else... } else { drawText(TimerText, 15, 25); //Draw text for the timer char xPos[100], yPos[100], zPos[100]; sprintf_s(xPos, "Camera X: %f", g_Camera.Position().x); sprintf_s(yPos, "Camera Y: %f", g_Camera.Position().y); sprintf_s(zPos, "Camera Z: %f", g_Camera.Position().z); drawText(xPos, 15, 45); drawText(yPos, 15, 65); drawText(zPos, 15, 85); perimeterCheck(); sprintf_s(LivesHUD, "Coins Collected: %d", CoinsCollected); drawText(LivesHUD, 15, 105); // Render the terrain as a simple quad - currently it is flat but it could be made into a terrain with a heightmap! 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(); glEnable(GL_BLEND);glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // additive blendingfloat blendFactor = 1.0;glColor4f(1, 0, 0, blendFactor); //blendFactor = 1glBegin(GL_QUADS); // Draw A QuadglVertex3f(-1.0f, 1.0f, 0.0f); // Top LeftglVertex3f( 1.0f, 1.0f, 0.0f); // Top RightglVertex3f( 1.0f,-1.0f, 0.0f); // Bottom RightglVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left // Bottom LeftglEnd();glEnable(GL_DEPTH_TEST); glGetError(); } SwapBuffers(g_hDC); // Swap the backbuffers to the foreground}[/source]

Edited by gurps, 31 July 2012 - 12:57 PM.


#4 JWalsh   Moderators   -  Reputation: 463

Like
2Likes
Like

Posted 31 July 2012 - 01:13 PM

In the intro screen section of your code you're drawing your quad with a counter-clockwise winding order. When you draw the red quad in your game-play section you're drawing the quad in a clockwise order. I suspect your quad is being treated as a back-facing primitive and is being culled out. Either switch the winding order or disable back-facing culling to verify.

Cheers and good luck!
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints

#5 gurps   Members   -  Reputation: 105

Like
0Likes
Like

Posted 31 July 2012 - 01:22 PM

In the intro screen section of your code you're drawing your quad with a counter-clockwise winding order. When you draw the red quad in your game-play section you're drawing the quad in a clockwise order. I suspect your quad is being treated as a back-facing primitive and is being culled out. Either switch the winding order or disable back-facing culling to verify.

Cheers and good luck!


Thank you for the reply...can you please explain more about the winding order as i've never heard of that? Anyway i commented out where i enabled back face culling and a small black square was rendered.
Posted Image

Where do i go from here?

#6 JWalsh   Moderators   -  Reputation: 463

Like
2Likes
Like

Posted 31 July 2012 - 01:45 PM

Winding Order
Any time you draw a triangle (or quad) there are two surfaces. One on the front of the triangle, and one on the back. When you draw a 3D shape such as a box, half of the surfaces are facing outward in space and are visible, the other half are facing inward, and are in theory, covered by the other side of the box. Unfortunately, unless you give the renderer specific instructions, it doesn't know which triangles are facing inside, and which are facing outside. So left to its own devices, it will try and draw all triangles. This often results in the back side of a 3D primitive drawing over the front side, which is a really disorienting effect, actually.

To solve the problem, the graphics engine can use the winding order of the primitives to determine whether something is front facing or back facing. Here's a little trick, take your pen, put it on paper and draw the three points of a triangle. Now, number them in a circle 0, 1, 2. Notice that if you flip the paper around, the numbers are in reverse order. That is, if you numbered them clockwise before, they are now counter-clockwise, and vice-versa.

This is the system the renderer uses to determine which "faces" should be drawn, and which shouldn't. You can tell the renderer to cull (don't draw) all clockwise surfaces, or you can tell it cull counter-clockwise surfaces. Or, if you disable back-face culling, it will draw all primitives. You're not noticing any adverse effects when disabling back-face culling because you're only drawing single primitives. Before moving on, however, you'll want to re-enable back-face culling and instead change the orientation of the vertices in your quad so they are consistent with the rest of your scene. As OpenGL is a right-handed system, I believe it disables clockwise primitives by default, which is why your red quad wasn't showing.You'll want to make sure whenever you add geometry to the scene, you do so in a counter-clockwise orientation.

World Space vs. Screen Space
Your quad is showing up small because you've got it drawing in the range of -1 to 1 at the origin of your scene. To make it draw over the entire scene, you either need to move it along with your camera and make it bigger, or you need to draw it in screen space using pre-transformed primitives. Given that you're not familiar with winding order, I'm going to guess that pre-transformed primitives is beyond you. So for now, make sure you specify the points of the quad as being just in front of your camera, and large enough that it covers the display area. It's not the correct approach, but it'll work for now.

Cheers and good luck!

Edited by JWalsh, 31 July 2012 - 01:47 PM.

Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints

#7 gurps   Members   -  Reputation: 105

Like
0Likes
Like

Posted 31 July 2012 - 02:15 PM

Winding Order

World Space vs. Screen Space
Your quad is showing up small because you've got it drawing in the range of -1 to 1 at the origin of your scene. To make it draw over the entire scene, you either need to move it along with your camera and make it bigger, or you need to draw it in screen space using pre-transformed primitives. Given that you're not familiar with winding order, I'm going to guess that pre-transformed primitives is beyond you. So for now, make sure you specify the points of the quad as being just in front of your camera, and large enough that it covers the display area. It's not the correct approach, but it'll work for now.

Cheers and good luck!


Thanks for the detailed reply.

How do I specify the size and position of the QUAD?

#8 JWalsh   Moderators   -  Reputation: 463

Like
0Likes
Like

Posted 31 July 2012 - 02:30 PM

How do I specify the size and position of the QUAD?


You're doing that with this code
[source lang="java"]glBegin(GL_QUADS); // Draw A QuadglVertex3f(-1.0f, 1.0f, 0.0f); // Top LeftglVertex3f( 1.0f, 1.0f, 0.0f); // Top RightglVertex3f( 1.0f,-1.0f, 0.0f); // Bottom RightglVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left[/source]
This says to create a 3D object with vertices located at (-1,1,0), (1,1,0), (1,-1,0) and (-1,-1,0). The first element is the position in the X coordinate, the second is the Y coordinate, and the third one, which is all 0's, is in the Z coordinate. If you increase the size, say 10 in each dimension it will make it 10x the size. That'll be fine for testing, but you need it to move around with your camera so that it shows up in front. So ultimately, the position of the quad needs to be based on your camera's position.

It sounds like you don't have a lot of experience with 3D math. I'd recommend reading a good book on computer graphics and 3D math before moving much further, or you're going to become overwhelmed pretty quickly.

Cheers!
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints

#9 wolfscaptain   Members   -  Reputation: 200

Like
0Likes
Like

Posted 01 August 2012 - 12:15 AM

Phone submitted twice for some reason.

#10 wolfscaptain   Members   -  Reputation: 200

Like
0Likes
Like

Posted 01 August 2012 - 12:17 AM

It will be a whole lot easier to use that same quad you defined, but before drawing it, reset your projection and view matrices.

I am not in front of a computer and I don't remember the exact synta, but something like this:
// draw your scene

glMatrixMode(GL_PROJECTION_MATRIX);
glPushMatrix(); // does this work for the projection matrix?
glLoadIdentity();
glMatrixMode(GL_MODELVIEW_MATRIX);
glPushMatrix();
glLoadIdentity();

// render your quad

glMatrixMode(GL_PROJECTION_MATRIX);
glPopMatrix();
glMatrixMode(GL_MODELVIEW_MATRIX);
glPopMatrix();

// ...

I haven't used the fixed pipeline for years, so I don't remember if pushing and poping matrices works for the projection matrix, but logically it should.

In any case, you can render that same quad in your code this way to make it "fullscreen".

As to seeing the other objects behind it - use blending (set your color with alpha below 1).




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS