ravi.joshi53's picture

GameWindow is looking reddish

I am rendering some textures using OpenTK. In between the game, I wanted to draw a point in red color. Now the entire window is looking reddish. When I changed the color to yellow, the point is rendered but this time window is yellowish . Below is the code, which draws a point-

private void drawPoint(float x, float y)
{
    GL.PushMatrix();
    GL.PointSize(20);
    GL.Begin(PrimitiveType.Points);
    GL.Color3(Color.Red);
    GL.Vertex2(x, y);
    GL.End();
    GL.PopMatrix();
}

Whats going wrong here?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Frassle's picture

You set the global Color variable in OpenGL to Red/Yellow. Unless you set it again every command that uses Color will be Red/Yellow. Clear is the most obvious offender for why your whole window changes color, make sure you call Color3 again before calling Clear.

ravi.joshi53's picture

Frassle, I would be best if I can set the color for the point and reset the color for other objects from this method only. Since resetting it in each object is quite irritating . Can you please tell post the required code for it...

winterhell's picture

You already have 7 lines of code in the function, you might as well add a GL.Color3(myDefaultColor); after you finished drawing the point

ravi.joshi53's picture

I am a bit confused now. See earlier I was drawing some rectangles with the same approach. Same like this and very easily I can assign any color at any time to any vertex.

Here in the above case, I don't have any default color. Since each texture is having there own color.

Frassle's picture

My bad clear uses it's own color variable so this won't affect that (haven't done immediate rendering in a while!)

It might be that the point is covering the whole screen (although 20 point size isn't that big)?
Are you sure this method is the only change? If you comment this method out (AND NOTHING ELSE) does the screen go back to normal?

ravi.joshi53's picture

Yes Frassle, If i comment this function everything rendered normally. Just by adding a color for the point, the whole screen is getting worse. Since I am using textures, following parameters are enabled globally-

GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);

Below is the code for texture drawing-

GL.PushMatrix();
GL.Enable(EnableCap.Texture2D);
GL.BindTexture(TextureTarget.Texture2D, texture);
// assign it to vertexes
GL.Disable(EnableCap.Texture2D);
GL.PopMatrix();

Above info may be helpful to trace the cause.

ravi.joshi53's picture

I forgot to tell you that I am using GL.ortho(0,800,0,600,-1,1); Point width 20 is not much here.

Also just now I noticed that after commenting GL.Color3(Color.Red);, the point is rendered in white color and rest of the window is normal and perfect.

Frassle's picture

Which version of OpenGL are you using? This may have changed at some point between 1 and 4.
Can you add GL.Color3(Color.White) just before GL.Clear and see if that fixes it (it shouldn't).

Also when you draw your point can you see it? Or does adding the DrawPoint code just turn the screen red?

the Fiddler's picture

GL.Color3 only works within a GL.Begin-GL.End region.

Have you tried disabling blending?

ravi.joshi53's picture
Frassle wrote:

when you draw your point can you see it?

Yes, I can see it (although screen is reddish)

Frassle wrote:

does adding the DrawPoint code just turn the screen red?

Yes Frassle, If i comment DrawPoint function everything rendered normally. Just by adding a color for the point, the whole screen is getting worse.