0

I'm going through OpenGL 3.3+ tutorial written in C++ and I'm converting my code to C# (using OpenTK). In the tutorial there's a VectorBufferObject using vector<BYTE> to hold data for buffer. Unfortunately I did not manage to achieve same functionality using List<byte>, because I was unable to convert Vector3 to byteArray the way it could be used by DrawArrays function.

But well, I've decided to store List<float> instead and following the tutorial I store all floats (3 for position + 2 for texture coords for each vertice) in a single List of VectorBufferObject.

Apart from not rendering textures properly (my mistake I believe, not important at the moment really) it should work just fine, BUT - it should render a cube and a pyramid rotating - it does render a triangle and a rectangle. I've checked it with PolygonMode.Line and I can tell that the rectangle is made of more than 2 triangles (it has box-type lines going across, not a single one that should be there when drawn with 2 triangles)). I therefore suspect they are drawn one over another. I can't figure out why really.

Below is source code of relevant classes. Please ask if there is a need for more information.

@EDIT Despite my huge hope of following the tutorial, I'd consider an alternative, not overly complicated alternative to that solution.

RenderingEngine.cs http://pastebin.com/gtnX4ESg

VectorBufferObject.cs http://pastebin.com/veGwybp7

Static_Geometry.cs http://pastebin.com/K1bJ8z8u

pzaj
  • 1,062
  • 1
  • 17
  • 37
  • There are two ways to convert Vector3 to byte[]. Since it's a struct the first way would be to marshall it ( http://stackoverflow.com/questions/3278827/how-to-convert-a-structure-to-a-byte-array-in-c ). The second way is using buffer.blockcopy ( https://msdn.microsoft.com/en-us/library/system.buffer.blockcopy%28v=vs.110%29.aspx ) – Vengarioth Apr 11 '15 at 10:02
  • thanks for Your information, will that work for OpenTK? and what about the main question, could You see any mistake I've made? ;> And which one would you suggest going with? Marshalling or blockcopy? – pzaj Apr 13 '15 at 06:10
  • It will work for OpenTK. I use blockcopy for vertex data and marshalling for uniform structs. I will have a look at your code, but have you tried GL.GetError(); for debugging? – Vengarioth Apr 13 '15 at 07:34
  • actually I did not, as everything seems to work fine... I tried few more things and here is an update (I decided to post it on OpenTK forum): http://www.opentk.com/node/3977. I will really appreciate if you'd have a look at my code. Maybe I've missed something I can't see... – pzaj Apr 13 '15 at 08:08
  • I'll give it a show (GetError) and see what's the return value. – pzaj Apr 13 '15 at 08:17
  • I'm getting error `InvalidOperation` in line `GL.Uniform4(iColorLoc, vBoxColors[i]);` in last loop (the one rendering colored translucent cubes). I don't believe that's causing my problems, but would be nice to solve it as well. – pzaj Apr 13 '15 at 08:43
  • Ok, I solved that one now... seems like I forgot to change program and got wrong locations of attributes for the shader. It quite works now, just my cubes aren't cubes still. – pzaj Apr 13 '15 at 08:50
  • I posted an update on openTK forum with a new screen and updated renderingEngine class. – pzaj Apr 13 '15 at 09:39

0 Answers0