Understanding OpenGL. I use OpenGL + SDL on Go, but probably it is not so important, it looks like my mistake is in the OpenGL API calls.

I'm trying to work with the camera, but I can not see anything, just a black screen.

First, I set up a projection:

gl.Viewport(0, 0, screenWidth, screenHeight) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() glu.Perspective(45, screenWidth/screenHeight, 0.1, 100) 

After that install the camera:

 gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() glu.LookAt( 10, 10, 5, 0, 0, 0, -1, -1, 1) 

After that I try to draw the following:

 gl.Clear(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT) gl.Color4f(1, 1, 1, 1) gl.Begin(gl.QUADS) gl.Vertex3d(-20, 20, 0) gl.Vertex3d(20, 20, 0) gl.Vertex3d(20, -20, 0) gl.Vertex3d(-20, -20, 0) gl.End() 

But I see only a black screen. Most likely, I somehow do not set up the camera / projection. If suddenly the error is somewhere else here is the complete code .

  • @Vladimir VG For fun, how was the problem finally solved? - Costantino Rupert
  • I did not dare at all, I took someone else’s working example and started modifying it for myself. There was a problem in some unknown detail for me. - Vladimir Gordeev

2 answers 2

On the go without a compiler is difficult to debug. Here, the order of calls is most likely incorrect in some place. Also try drawing two triangles instead of a rectangle.


 //Было: gl.Begin(gl.QUADS) //Стало gl.Begin(gl.GL_QUADS) //И так со всеми константами. Странно что они без перфикса в имени. //Хотя наверное это особенность реализации OpenGL на Go и это неверно. 

Another idea:

 gl.Color4f(1, 1, 1, 1) //Прозрачный белый цвет накладывается на то что уже есть в frambuffeе, а там по умолчанию черный прямоуголньик, поэтому вам и выдает пустой экран. Поробуйте что-нибудь вроде. gl.Color4f(0.5, 0.5, 0.5, 0.5) //Здесь я тоже ошибся 1 = непрозрачность. Так что эта строка правильная. 

    Try instead of glu.LookAt() use the following function:

     glTranslatef(0,0,-3); glRotatef (-45, 1.0, 0.0 , 0.0); glRotatef (0, 1.0, 0.0 , 0.0); glRotatef (-90, 0.0, 0.0 , 1.0); 

    It seems the coordinates are wrong here, try to look around changing values

    • No, it did not help. A little play with the coefficients - also nothing. - Vladimir Gordeev September
    • I normally show your code. Delphi 7. And you SwapBuffers(DC); doing after drawing? - ViruSkin
    • Yes, the link is the complete code, there are SwapBuffers. Thanks for the info, I will continue to think. - Vladimir Gordeev September