
Usage problem with InterleavedArrays
Posted Saturday, 15 December, 2012 - 13:58 by libery inHy,
I have already use InterleavedArrays with openGL, however, my openTk code does not.
Can you help me for my problem?
This is my full code for program.cs file :
using System; using System.Collections.Generic; using OpenTK; using OpenTK.Graphics; using OpenTK.Graphics.OpenGL; using OpenTK.Audio; using OpenTK.Audio.OpenAL; using OpenTK.Input; namespace OpenTk_Test3_InterleavedArrays { class Game : GameWindow { uint myBufferHandle = 0; float[] interleavedData; /// <summary>Creates a 800x600 window with the specified title.</summary> public Game() : base(800, 600, GraphicsMode.Default, "OpenTk Test3 InterleavedArrays") { VSync = VSyncMode.On; } /// <summary>Load resources here.</summary> /// <param name="e">Not used.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); GL.ClearColor(1.0f, 1.0f, 1.0f, 0.0f); GL.Enable(EnableCap.DepthTest); interleavedData = new float[24]; // T + N + V = (2*3*3) * nombre de point = (2*3*3)*3 = 24 // Attribution du point 1 interleavedData[0] = 0; // u de t1 interleavedData[1] = 0; // v de t1 interleavedData[2] = 0; // x de n1 interleavedData[3] = 0; // y de n1 interleavedData[4] = 0; // z de n1 interleavedData[5] = -1; // x de v1 interleavedData[6] = -1; // y de v1 interleavedData[7] = 4; // z de v1 // Attribution du point 2 interleavedData[8] = 0; // u de t2 interleavedData[9] = 0; // v de t2 interleavedData[10] = 0; // x de n2 interleavedData[11] = 0;// y de n2 interleavedData[12] = 0;// z de n2 interleavedData[13] = 1; // x de v2 interleavedData[14] = -1; // y de v2 interleavedData[15] = 4; // z de v2 // Attribution du point 3 interleavedData[16] = 0; // u de t3 interleavedData[17] = 0; // v de t3 interleavedData[18] = 0; // x de n3 interleavedData[19] = 0; // y de n3 interleavedData[20] = 0; // z de n3 interleavedData[21] = 0; // x de v3 interleavedData[22] = 1; // y de v3 interleavedData[23] = 4; // z de v3 GL.GenBuffers(1, out myBufferHandle); GL.BindBuffer(BufferTarget.ArrayBuffer, myBufferHandle); GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(24 * sizeof(float)), interleavedData, BufferUsageHint.StaticDraw); GL.InterleavedArrays(InterleavedArrayFormat.T2fN3fV3f, 0, (IntPtr)null); } /// <summary> /// Called when it is time to render the next frame. Add your rendering code here. /// </summary> /// <param name="e">Contains timing information.</param> protected override void OnRenderFrame(FrameEventArgs e) { base.OnRenderFrame(e); GL.ClearColor(Color4.Blue); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, Vector3.UnitZ, Vector3.UnitY); GL.MatrixMode(MatrixMode.Modelview); GL.LoadMatrix(ref modelview); GL.EnableClientState(ArrayCap.VertexArray); GL.BindBuffer(BufferTarget.ArrayBuffer, myBufferHandle); GL.InterleavedArrays(InterleavedArrayFormat.T2fN3fV3f, 0, IntPtr.Zero); GL.DrawArrays(BeginMode.Triangles, 0, 24*sizeof(float)); GL.DisableClientState(ArrayCap.VertexArray); SwapBuffers(); } [STAThread] static void Main(string[] args) { using (Game game = new Game()) { game.Run(30.0); } } } }
Thank you


Comments
Re: Usage problem with InterleavedArrays
You can interleave your array data with something like this:
Take a look at the GeometryShaderAdvanced.cs example. I guess glInterleavedArrays is an older and deprecated call. The GL.VertexPointer, etc has the plus of being opengles 2.0 as well as working on all the desktop platforms. Plus you have lots of examples to go off of.
I also didn't double check to make sure your coordinates were actually in the viewscreen, that's usually what goes wrong for me.
Re: Usage problem with InterleavedArrays
Thank you for this answer.
The code written in the answer is to integrate in my code ? Or it is an other solution to get my goal ?
Re: Usage problem with InterleavedArrays
You'll need to adjust it slightly for your case. InterleavedArrayFormat.T2fN3fV3f is in a different order. But look at the GeometryShaderAdvanced.cs as an example. I can't really rewrite your program for you with this approach.
https://github.com/mono/opentk/blob/master/Source/Examples/OpenGL/2.x/Ge...
Re: Usage problem with InterleavedArrays
thank you,
I pass by this method, because my need is import all objfile, and several obj files has multiple texture coordinates for one vertex in terms of faces.
Sorry for my english, i am french.
I will look your file example.