Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am learning OpenGL using OpenTK and VB.NET. I made a square with a texture:

    GL.Begin(BeginMode.Quads)
    GL.TexCoord2(0.0, 0.0)
    GL.Vertex3(-1.0, 1.0, 0.0)
    GL.TexCoord2(1.0, 0.0)
    GL.Vertex3(1.0, 1.0, 0.0)
    GL.TexCoord2(1.0, 1.0)
    GL.Vertex3(1.0, -1.0, 0.0)
    GL.TexCoord2(0.0, 1.0)
    GL.Vertex3(-1.0, -1.0, 0.0)
    GL.End()

This works fine and produces this image:

enter image description here

When I add GL.Color4, the whole screen is completely blank. This is what my code looks like:

    GL.Color4(100, 100, 100, 255)
    GL.Begin(BeginMode.Quads)
    GL.TexCoord2(0.0, 0.0)
    GL.Vertex3(-1.0, 1.0, 0.0)
    GL.TexCoord2(1.0, 0.0)
    GL.Vertex3(1.0, 1.0, 0.0)
    GL.TexCoord2(1.0, 1.0)
    GL.Vertex3(1.0, -1.0, 0.0)
    GL.TexCoord2(0.0, 1.0)
    GL.Vertex3(-1.0, -1.0, 0.0)
    GL.End()

Here is an additional piece of code:

    GL.ShadeModel(ShadingModel.Smooth)
    GL.ClearColor(Color.Black)
    GL.ClearDepth(1.0)

    GL.Enable(EnableCap.Texture2D)
    GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.One)
    GL.Enable(EnableCap.Blend)

    GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest)
share|improve this question
1  
It's worth pointing out that the functionality you're learning (OpenGL's immediate mode, using glBegin, et cetera) is deprecated in modern OpenGL and may not necessarily be the best investment of your time unless you cannot run modern OpenGL. –  Josh Petrie Jul 24 '13 at 16:02
1  
What Josh said, but also, are you sure those values to GL.Color aren't supposed to be in [0,1] ? e.g. GL.Color(0.3, 0.3, 0.3, 1.0) ? I can't find any worthwhile API docs on OpenTK so I haven't been able to check. –  Sean Middleditch Jul 24 '13 at 16:15
    
Using GL.Color4(0.3, 0.3, 0.3, 1.0) works. It is strange that Color4 has overloaded function for integer and it is also what NeHe tutorial is using (integer). –  Monkey D Luffy Jul 24 '13 at 16:25
    
Presumably the integer overrides should utilize things like glColor4ui under the hood. –  Josh Petrie Jul 24 '13 at 16:51
    
Didn't know there even were overloads; I couldn't find squat for API documentation for OpenTK. :/ –  Sean Middleditch Jul 24 '13 at 23:16
add comment

1 Answer

up vote 3 down vote accepted

The GL.Color* functions can only be used between GL.Begin and GL.End. Your code sample has the lone GL.Color4 call before GL.Begin. If you move it inside the begin/end block, you should see things again.

The most-likely reason this has led to a blank screen is that you're actually putting OpenGL into an error state and you're not retrieving any errors from OpenGL. If you had error handling code in place, you'd likely be seeing a message to the effect of "glColor must be called between glBegin and glEnd."

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.