Jump to content
  • Advertisement
Jens Eckervogt

OpenGL OpenTK - Why does wavefront not show up to viewport?

Recommended Posts

Posted (edited)

Hello guys, 

 

Please tell me! 

How do I know? Why does wavefront not show for me?

I already checked I have non errors yet.

using OpenTK;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Tutorial_08.net.sourceskyboxer
{
    public class WaveFrontLoader
    {
        private static List<Vector3> inPositions;
        private static List<Vector2> inTexcoords;
        private static List<Vector3> inNormals;

        private static List<float> positions;
        private static List<float> texcoords;
        private static List<int> indices;

        public static RawModel LoadObjModel(string filename, Loader loader)
        {
            inPositions = new List<Vector3>();
            inTexcoords = new List<Vector2>();
            inNormals = new List<Vector3>();

            positions = new List<float>();
            texcoords = new List<float>();
            indices = new List<int>();

            int nextIdx = 0;

            using (var reader = new StreamReader(File.Open("Contents/" + filename + ".obj", FileMode.Open), Encoding.UTF8))
            {
                string line = reader.ReadLine();
                int i = reader.Read();
                while (true)
                {
                    string[] currentLine = line.Split();

                    if (currentLine[0] == "v")
                    {
                        Vector3 pos = new Vector3(float.Parse(currentLine[1]), float.Parse(currentLine[2]), float.Parse(currentLine[3]));
                        inPositions.Add(pos);

                        if (currentLine[1] == "t")
                        {
                            Vector2 tex = new Vector2(float.Parse(currentLine[1]), float.Parse(currentLine[2]));
                            inTexcoords.Add(tex);
                        }

                        if (currentLine[1] == "n")
                        {
                            Vector3 nom = new Vector3(float.Parse(currentLine[1]), float.Parse(currentLine[2]), float.Parse(currentLine[3]));
                            inNormals.Add(nom);
                        }
                    }

                    if (currentLine[0] == "f")
                    {
                        Vector3 pos = inPositions[0];
                        positions.Add(pos.X);
                        positions.Add(pos.Y);
                        positions.Add(pos.Z);
                        Vector2 tc = inTexcoords[0];
                        texcoords.Add(tc.X);
                        texcoords.Add(tc.Y);
                        indices.Add(nextIdx);
                        ++nextIdx;
                    }

                    reader.Close();
                    return loader.loadToVAO(positions.ToArray(), texcoords.ToArray(), indices.ToArray());
                }
            }
        }
    }
}

And It have tried other method but it can't show for me. :( I am mad now. Because any OpenTK developers won't help me.
Please help me how do I fix.

And my download (mega.nz) should it is original but I tried no success...

- Add blend source and png file here I have tried tried,..... :( 

 

PS: Why is our community not active? I wait very longer. Stop to lie me!

Thanks !

Edited by Jens Eckervogt

Share this post


Link to post
Share on other sites
Advertisement
7 minutes ago, Jens Eckervogt said:

PS: Why is our community not active? I wait very longer. Stop to lie me!

You wrote just 7 minutes ago so come down and keep calm. People are working or sleeping depending on where on the world you are currently ... :)

Have you checked that your file is processed correctly by setting a breakpoint and investigate the contents of the arrays?

Have you checked for GLErrors?

Have you checked for other non-exceptional errors?

Have you setup your View- and Projection-Matrix aka the camera correctly?

Have you checked that your model gets rendered correctly so push to graphics card is triggered, shader is set up correctly and model/view/projection matrices are setup correctly?

Share this post


Link to post
Share on other sites

Thanks @Shaarigan

I already tried.. But object is sure correct and is exported from Blender 2.79 ( If you are sure that Blender ( latest version has bug or wrong object version )

My file from mega nz is original initial release but I have tried and it doesn't see to work for showing.

And GL.Errors doesn't show anything.... Somebody can explain why does Wavefront not show? Is it possible wrong parser or what?

Share this post


Link to post
Share on other sites
Posted (edited)

Hello Jens,

 

Just by looking at the code I don't see where you are populating the "indices" List. It seems to me that it is always empty.

 

EDIT: Another thing. I see that everytimes you meet a face instruction (the "f" token) you completely discard all your arrays and create a new one to repopulate it entirely. This is really not optimal and will result in long loading time even on relatively simple models.

Edited by ChuckNovice

Share this post


Link to post
Share on other sites
2 hours ago, Jens Eckervogt said:

>PLEASE HELP ME HOW DO I FIX WAVEFRONT LOAD IN GAMEWINDOW

I have no idea who uses OpenTK here as I'm sure most people using C# are either on the Unity or Mono train.

It took me under 15 seconds to find a lot of resources online. Why don't you try following a tutorial online such as this series:

 

There are even more tutorials online: https://www.codeproject.com/Articles/1167212/OpenGL-with-OpenTK-in-Csharp-Part-Initialize-the-G

You really need to relax, I see you've already filled out the OpenTK chat room and they already told you that you wont be spoon fed code, so make sure you understand what you're doing with OpenTK and C#, then run your debugger to find out what isn't loading right.

https://gitter.im/opentk/opentk

 

 

Share this post


Link to post
Share on other sites
Posted (edited)

Why are you use old version? Please check github OpenT! It is really very latest but I found SharpGL's Objfileloader it looks shit I really want use only Lists with Vector2, Vector3 and float and int.

I have problem with while loop with StreamReader + continue and break; if you know how does program read to wavefront file like

Vt, vn, v and f 

But i really don't know how do i skip unusable lines like #, o and s?

Thanks

Edited by Jens Eckervogt

Share this post


Link to post
Share on other sites
Just now, Jens Eckervogt said:

Why are you use old version? Please check github OpenT! It is really very latest but I found SharpGL's Objfileloader it looks shit I really want use only Lists with Vector2, Vector3 and float and int.

I have problem with while loop with continue and break; if you know how does program read to wavefront file like

Vt, vn, v and f 

But i really don't know how do i skip unusable lines like #, o and s?

Thanks

Okay, best of luck. :) 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!