• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
robee00

Loading OBJ model to VBO

5 posts in this topic

Hello guys.

 

I came across a problem today. I exported a single cube from blender, and I tried to wrote a simple .obj loader to use. I think my parsing method is okay, but I have problem putting the data into a vbo/ibo. The vertex and fragment shader is working, I used them before. What I get is a deformated cube. Like faces (quad) only got one of the tris drawn.

 

Vertex class contains fields for position, texcoords, and normals

 

FaceData just holds the ID for vertex, texcoord and normal.

public class Model {

    ArrayList<Vertex> vertices = new ArrayList<Vertex>();
    ArrayList<Vector3f> pos = new ArrayList<Vector3f>();
    ArrayList<Vector2f> tex = new ArrayList<Vector2f>();
    ArrayList<Vector3f> norm = new ArrayList<Vector3f>();
    ArrayList<FaceData> faces = new ArrayList<FaceData>();

    int vbo;
    int ibo;

    public int indexCount;

    public Model(String name)
    {
        parseObj(name);

        FloatBuffer vertBuffer = BufferUtils.createFloatBuffer(vertices.size() * 8);

        for(Vertex v : vertices)
        {
            vertBuffer.put(v.getElements());
        }

        vertBuffer.flip();

        vbo = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertBuffer, GL15.GL_STATIC_DRAW);
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

        IntBuffer indices = BufferUtils.createIntBuffer(faces.size());

        for(FaceData f : faces)
        {
            indices.put(f.vertexID - 1);
            indexCount++;
        }

        indices.flip();

        ibo = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo);
        GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STATIC_DRAW);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    }

    public void render()
    {
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);

        GL20.glEnableVertexAttribArray(0);
        GL20.glEnableVertexAttribArray(1);
        GL20.glEnableVertexAttribArray(2);

        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
        GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 32, 0);
        GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, 32, 12);
        GL20.glVertexAttribPointer(2, 3, GL11.GL_FLOAT, false, 32, 20);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo);
        GL11.glDrawElements(GL11.GL_TRIANGLES, indexCount, GL11.GL_UNSIGNED_INT, 0);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);

        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

        GL20.glDisableVertexAttribArray(0);
        GL20.glDisableVertexAttribArray(1);
        GL20.glDisableVertexAttribArray(2);

        GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
    }

    public void parseObj(String path)
    {
        try {
            BufferedReader reader = new BufferedReader(new FileReader(new File("").getAbsolutePath() + "/res/" + path));

            String line = reader.readLine();

            while(line != null)
            {
                if(line.startsWith("v "))
                {
                    int start = line.indexOf(" ");
                    String sub = line.substring(start + 1);

                    String[] vertexStr = sub.split(" " );

                    pos.add(new Vector3f(Float.parseFloat(vertexStr[0]), Float.parseFloat(vertexStr[1]), Float.parseFloat(vertexStr[2])));
                }
                if(line.startsWith("vt "))
                {
                    int start = line.indexOf(" ");
                    String sub = line.substring(start + 1);

                    String[] vertexStr = sub.split(" " );

                    tex.add(new Vector2f(Float.parseFloat(vertexStr[0]), Float.parseFloat(vertexStr[1])));
                }
                if(line.startsWith("vn "))
                {
                    int start = line.indexOf(" ");
                    String sub = line.substring(start + 1);

                    String[] vertexStr = sub.split(" " );

                    norm.add(new Vector3f(Float.parseFloat(vertexStr[0]), Float.parseFloat(vertexStr[1]), Float.parseFloat(vertexStr[2])));
                }
                if(line.startsWith("f "))
                {
                    int start = line.indexOf(" ");
                    String sub = line.substring(start + 1);

                    String[] vertexStr = sub.split(" ");

                    for(int i = 0; i < vertexStr.length; i++)
                    {
                        String[] verStr = vertexStr[i].split("/");

                        FaceData data = new FaceData();
                        data.vertexID = Integer.parseInt(verStr[0]);
                        //data.texID = Integer.parseInt(verStr[1]);
                        data.normalID = Integer.parseInt(verStr[2]);
                        faces.add(data);
                    }
                }

                line = reader.readLine();
            }

            reader.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        for(int i = 0; i < faces.size(); i++)
        {
            Vertex v = new Vertex();
            v.pos = pos.get(faces.get(i).vertexID - 1);
            v.texCoord = new Vector2f(0,0);
            v.normal = norm.get(faces.get(i).normalID - 1);

            vertices.add(v);
        }
    }

}

Edited by RobeeZ
0

Share this post


Link to post
Share on other sites

Found some old code: its marked as working but i dont use it:

void __fastcall TachoGLModel::LoadFromOBJfile(AnsiString filename)
{
TStringList * k = new TStringList();

    k->LoadFromFile(filename);
	   int r;
	   for (r = 0; r < k->Count; r++) {
		 //  ShowMessage(k->Strings[r]);
		 if (Pos("# 2933 faces",k->Strings[r]) > 0 ) {
													ShowMessage("KONIEC");
		 }
	   }



return;
char buff[1024];
int vcnt = 0;

TMemoryStream * obj = new TMemoryStream();
obj->LoadFromFile(filename);
obj->Position = 0;

AnsiString s;
int i;

//ShowMessage(IntToStr(obj->Size/1024)+ " kb");

//i = 20 * obj->Size / 1024; //zczytuj za jednym razem 10 kb
int cnt = 0;


while (obj->Position < obj->Size) {
obj->Read((void*)buff,1024);
s = buff;


cnt = cnt + 1;

k->Text = s;

//ShowMessage("COUNT : "+IntToStr(cnt) + "   POS: " + IntToStr(obj->Position) + "   TYP TEXT: "+s);


for (i = 0; i < k->Count; i++) {
s = k->Strings[i];
if ( (s.Length() > 7) && (Pos("v",LowerCase(s)  ) > 0)  && (numberofchars(s, " ") == 3)  &&
 (s[1] == 'v') &&  (s[2] == ' ')  && (OBJ_LINE_TEST_IS_VERTEX(s) == true)  ) vcnt = vcnt + 1;


 }



}
 


USE_COLOR_MAP = false;

VBO_V.set_length(vcnt);
VBO_N.set_length(vcnt);
VBO_T.set_length(vcnt);
VBO_BE.set_length(1);
VBO_BE[0].INDEX_START = 0;
VBO_BE[0].length = VBO_V.Length-2;

//ShowMessage("V  "+IntToStr(VBO_V.Length));
//ShowMessage("T  "+IntToStr(VBO_T.Length));
//ShowMessage("N  "+IntToStr(VBO_N.Length));
//ShowMessage("BE  "+IntToStr(VBO_BE.Length));
//ShowMessage("Matrixarr  "+IntToStr(Matrixarr.Length));
//ShowMessage("Texindex  "+IntToStr(Textureindex.Length));
//ShowMessage("Tekstury  "+IntToStr(Textures.Length));


//VBO_C.set_length(vcnt*4);
//header.USEN = false;header.USET = false;

Matrixarr.set_length(1);
Textureindex.set_length(1);
Textures.set_length(1);
//
//for (i = 0; i < Matrixarr.Length; i++) {
//Matrixarr[i] 	= mtTriangles;
//Textureindex[i] = 0;
//}


Matrixarr[0] 	= mtTriangles;

cnt = -1;
obj->Position = 0;

int facei=0;

vcnt = -1;

while (obj->Position < obj->Size) {
obj->Read((void*)buff,1024);
s = buff;


cnt = cnt + 1;

k->Text = s;


for (i = 0; i < k->Count; i++) {
s = k->Strings[i];

if ( (s.Length() > 7) && (Pos("v",LowerCase(s)  ) > 0)  && (numberofchars(s, " ") == 3)  &&
 (s[1] == 'v') &&  (s[2] == ' ')  && (OBJ_LINE_TEST_IS_VERTEX(s) == true)  ) { //to jest vertex


 vcnt = vcnt + 1;
if (vcnt >= VBO_V.Length ) {break; break; }

  VBO_V[vcnt] = OBJ_LINE_TO_T3dPOINT(s);
  VBO_N[vcnt] = triplesingletoT3DPOINT(0,0,1);
  VBO_T[vcnt].x = 0;   VBO_T[vcnt].y = 0;



}







}


}
 













delete obj;

delete k;


//ShowMessage(IntToStr(vcnt));
}

 

 

 

I use this:

 



bool OBJ_LINE_TEST_IS_VERTEX(AnsiString s)
{


s = StringReplace(s,".","," ,TReplaceFlags() << rfReplaceAll);
float a = -101001.0101f;
t3dpoint result;

get_all_in_nawias(s, " ",4);
//ShowMessage(w_nawiasie[4][0]);
//ShowMessage(w_nawiasie[4][1]);
//ShowMessage(w_nawiasie[4][2]);
//ShowMessage(w_nawiasie[4][3]);
result.x = StrToFloatDef(w_nawiasie[4][1],a);
result.y = StrToFloatDef(w_nawiasie[4][2],a);
result.z = StrToFloatDef(w_nawiasie[4][3],a);
//ShowMessage(showmsg3flt(result));

if ( (result.x != a) && (result.y != a) && (result.z != a) )
return true; else return false;

}

t3dpoint OBJ_LINE_TO_T3dPOINT(AnsiString s)
{
t3dpoint result;


get_all_in_nawias(s, " ",4);
result.x = pstrtofloat(w_nawiasie[4][1]);
result.y = pstrtofloat(w_nawiasie[4][2]);
result.z = pstrtofloat(w_nawiasie[4][3]);
//ShowMessage(showmsg3flt(result));


return result;
}


textpoint OBJ_LINE_TO_TEXTPOINT(AnsiString s)
{
textpoint result;


get_all_in_nawias(s, " ",4);
result.x = pstrtofloat(w_nawiasie[4][1]);
result.y = pstrtofloat(w_nawiasie[4][2]);

return result;
}





void __fastcall TachoGLModel::LOAD_WAVEFRONT_MATERIAL_FILE_FROM_OBJ(AnsiString filename, AnsiString toFILE)
{                  /*
AnsiString Vertex1, TexCoord1;
AnsiString Vertex2, TexCoord2;
AnsiString Vertex3, TexCoord3;
OBJ_MATERIALS MATERIALS;
TStringList * MTLLIB = new TStringList();

MTLLIB->LoadFromFile(ExtractFilePath(filename)+change_filename_ext(filename,"mtl"));
						// MTLLIB->LoadFromFile(filename);
int mtl_cnt = 0;

 for (int i = 0; i < MTLLIB->Count; i++) {
	  if (Pos("newmtl ",LowerCase(MTLLIB->Strings[i]) ) > 0) {
		   mtl_cnt = mtl_cnt + 1;

	  }
 }


MATERIALS.set_length(mtl_cnt);


mtl_cnt = -1;

 for (int i = 0; i < MTLLIB->Count; i++) {
	  if (Pos("newmtl ",LowerCase(MTLLIB->Strings[i]) ) > 0) { //znalazlem nowy materia?
mtl_cnt = mtl_cnt + 1;
if (mtl_cnt > MATERIALS.Length-1) {
//ShowMessage("CPS");

}

MATERIALS[mtl_cnt].MaterialName = get_after_char2(MTLLIB->Strings[i]," ");

for (int j = i+1; j < MTLLIB->Count; j++) {

AnsiString OUTPUT = StringReplace(MTLLIB->Strings[j],".","," ,TReplaceFlags() << rfReplaceAll);
if (Pos("Kd ",OUTPUT) > 0 ) {


FCyfra->SZUAJPLIKOW1->get_all_in_nawias2(OUTPUT," ",0);


//ShowMessage(OUTPUT);
//ShowMessage(IntToStr(FCyfra->SZUAJPLIKOW1->w_nawiasiec[0].Length));
//				   ShowMessage(FCyfra->SZUAJPLIKOW1->w_nawiasiec[0][1]);
//								   ShowMessage(FCyfra->SZUAJPLIKOW1->w_nawiasiec[0][2]);
//												   ShowMessage(FCyfra->SZUAJPLIKOW1->w_nawiasiec[0][3]);
//											  ShowMessage(FCyfra->SZUAJPLIKOW1->w_nawiasiec[0][4]);
//											                         ShowMessage(FCyfra->SZUAJPLIKOW1->w_nawiasiec[0][5]);

MATERIALS[mtl_cnt].Diffuse[0] = StrToFloat(FCyfra->SZUAJPLIKOW1->w_nawiasiec[0][1]);
MATERIALS[mtl_cnt].Diffuse[1] = StrToFloat(FCyfra->SZUAJPLIKOW1->w_nawiasiec[0][2]);
MATERIALS[mtl_cnt].Diffuse[2] = StrToFloat(FCyfra->SZUAJPLIKOW1->w_nawiasiec[0][3]);
//ShowMessage(IntToStr(mtl_cnt)+ "      "+FloatToStr(MATERIALS[mtl_cnt].Diffuse[0]));
//ShowMessage(IntToStr(mtl_cnt)+ "      "+FloatToStr(MATERIALS[mtl_cnt].Diffuse[1]));
//ShowMessage(IntToStr(mtl_cnt)+ "      "+FloatToStr(MATERIALS[mtl_cnt].Diffuse[2]));
MATERIALS[mtl_cnt].Diffuse[3] = 1.0f;
break;
					   }

										}


	  }
 }

mtl_cnt = -1;

delete MTLLIB;

//------------------------------------------------------------------------------POPAWNE ZA?ADOWANIE WARTOSCI MATERIALOW


VBO_C.set_length(VBO_V.Length*4);

TStringList * p = new TStringList();
TStringList * k = new TStringList();
TStringList * MATERIAL_FILE = new TStringList();

AnsiString s;	k->LoadFromFile(filename);

USE_COLOR_MAP = false;
int i;
//dobhra tutaj juz mamy wyliczone kolory vertexow
		 int fcnt=0;
//a tutaj
 int r;
	   for (r = 0; r < k->Count; r++) {
	 s = k->Strings[r];
		  if  (Pos("f ",LowerCase(s)) > 0)  fcnt = fcnt + 1;

		  if  ( (Pos("usemtl",LowerCase(s)) > 0) && Pos("#",LowerCase(s)) == 0) {

	  for (int c=0; c < MATERIALS.Length; c++) {
  if (	   LowerCase(MATERIALS[c].MaterialName) == LowerCase(get_after_char2(s," ")) )

MATERIAL_FILE->Add("NEW_MATERIAL_ON_FACE("+IntToStr(fcnt)+"."+FloatToStr(MATERIALS[c].Diffuse[0])+"."+FloatToStr(MATERIALS[c].Diffuse[1])+"."+FloatToStr(MATERIALS[c].Diffuse[2])+");");
//MATERIAL_FILE->SaveToFile("C:\\TESTMATERIAL.TXT");
	  }

	  }
	  }

  //	  ShowMessage("*");

//NEW_MATERIAL_ON_FACE(	NUM . R . G . B  );

AnsiString piok;
//FCyfra->SZUAJPLIKOW1->w_nawiasiec[0][0] = NEW_MATERIAL_ON_FACE(	NUM
for (int i=0; i < MATERIAL_FILE->Count; i++) {

FCyfra->SZUAJPLIKOW1->get_all_in_nawias2(MATERIAL_FILE->Strings[i],".",0);
piok= get_after_char2(FCyfra->SZUAJPLIKOW1->w_nawiasiec[0][0],"(");
int faceI = StrToInt(piok.c_str());

FCyfra->SZUAJPLIKOW1->w_nawiasiec[0][3] = get_before_char(FCyfra->SZUAJPLIKOW1->w_nawiasiec[0][3],");",false);

float R = StrToFloat( FCyfra->SZUAJPLIKOW1->w_nawiasiec[0][1]);
float G = StrToFloat( FCyfra->SZUAJPLIKOW1->w_nawiasiec[0][2]);
float B = StrToFloat( FCyfra->SZUAJPLIKOW1->w_nawiasiec[0][3]);
if (i != MATERIAL_FILE->Count-1) {
FCyfra->SZUAJPLIKOW1->get_all_in_nawias2(MATERIAL_FILE->Strings[i+1],".",0);
									   piok = get_after_char2(FCyfra->SZUAJPLIKOW1->w_nawiasiec[0][0],"(");
  int NextfaceI = StrToInt(piok.c_str());




  for (int j = faceI; j < NextfaceI; j++) {

  for (int v = VBO_BE[j].INDEX_START; v < VBO_BE[j].INDEX_START+VBO_BE[j].length; v++) {
VBO_C[v*4] = R;
VBO_C[v*4+1] = G;
VBO_C[v*4+2] = B;
VBO_C[v*4+3] = 1.0f;
  }

  }

  }



		  }





//  for (int ji = 0; ji < MATERIALS.Length; ji++) {
//
//p->Add(  MATERIALS[ji].MaterialName+ "   R   "+ FloatToStr(MATERIALS[ji].Diffuse[0]));
//p->Add(  MATERIALS[ji].MaterialName+ "   G   "+ FloatToStr(MATERIALS[ji].Diffuse[1]));
//p->Add(  MATERIALS[ji].MaterialName+ "   B   "+ FloatToStr(MATERIALS[ji].Diffuse[2]));
//  }

AnsiString result=            ExtractFilePath(filename);
p->SaveToFile(result+"FFF.TXT");

delete p;

delete k;// = new TStringList();

delete MATERIAL_FILE;// = new TStringList();*/
}


//X:\\Projects\\tachoPORT2\\OpenGL\\Models\\Obj\\8243_Scania_143
void __fastcall TachoGLModel::LoadFromOBJfile(AnsiString filename)
{
int vcnt = 0;
int fcnt = 0;


int i;


TStringList * k = new TStringList();

TStringList * obj = new TStringList();
TStringList * MATERIAL_FILE = new TStringList();

TStringList * VE = new TStringList();

		 AnsiString s;
	k->LoadFromFile(filename);
	   int r;
	   for (r = 0; r < k->Count; r++) {
	 s = k->Strings[r];
		  if ( (Pos("v ",LowerCase(s)) > 0) && (numberofchars(s,".") == 3) )  vcnt = vcnt + 1;

		  if  (Pos("f ",LowerCase(s)) > 0)  fcnt = fcnt + 1;
		  if  ( (Pos("usemtl",LowerCase(s)) > 0) && Pos("#",LowerCase(s)) == 0)  MATERIAL_FILE->Add("NEW_MATERIAL_ON_FACE("+IntToStr(fcnt+1)+");");

		  //usemtl BLACK_MATT
	 }
//teraz ma by? zczytanie danych z pliku drugi pass    TYLKO VERTEXY
//TStringList * TE = new TStringList();

vcnt = -1;
fcnt = -1;


// POBRANIE LISTY VERTEXOW DO JEDNORODNEJ LISTY
for (r = 0; r < k->Count; r++) {
s = k->Strings[r];
if ( (Pos("v ",LowerCase(s)) > 0) && (numberofchars(s,".") == 3) )  {

if (numberofchars(s,"//") > 3 ) {ShowMessage("ERRORNEUS FACE");}

VE->Add(s);
}}


//III PASS zczytanie informacji o face'ach i przypozadkowanie z VBO_N vertexow do VBO_V


fcnt = -1;

AnsiString Vertex1, TexCoord1;
AnsiString Vertex2, TexCoord2;
AnsiString Vertex3, TexCoord3;

for (r = 0; r < k->Count; r++) {
s = k->Strings[r];


 if  (Pos("f ",LowerCase(s)) > 0) { //to jest face
	 fcnt = fcnt + 1;



get_all_in_nawias(s, " ",4);
//if (w_nawiasie[4].Length != 4) ShowMessage(s);

Vertex1 = get_before_char(w_nawiasie[4][1],"/",false);
Vertex2 = get_before_char(w_nawiasie[4][2],"/",false);
Vertex3 = get_before_char(w_nawiasie[4][3],"/",false);



//TexCoord1 = get_after_char(w_nawiasie[4][1],"/",false);
//TexCoord2 = get_after_char(w_nawiasie[4][2],"/",false);
//TexCoord3 = get_after_char(w_nawiasie[4][3],"/",false);
int a,b,c;
	   a=AStringToInt(Vertex1);
	   b=AStringToInt(Vertex2);
	   c=AStringToInt(Vertex3);



//int auv,buv,cuv;


//	   auv=AStringToInt(TexCoord1);
//	   buv=AStringToInt(TexCoord2);
//	   cuv=AStringToInt(TexCoord3);


if ( (a  <= VE->Count) && (b   <= VE->Count) &&
(c   <= VE->Count) ) {

obj->Add("begin(GL_TRIANGLES);");

//obj->Add("glTexCoord2f("+TEXTPOINT_TO_BGLCMD(	OBJ_LINE_TO_TEXTPOINT(VE->Strings[auv-1]	))+");");
obj->Add("glVertex3f("+POINT_TO_BGLCMD(	OBJ_LINE_TO_T3dPOINT(VE->Strings[a-1]	))+");");

//obj->Add("glTexCoord2f("+TEXTPOINT_TO_BGLCMD(	OBJ_LINE_TO_TEXTPOINT(VE->Strings[buv-1]	))+");");
obj->Add("glVertex3f("+POINT_TO_BGLCMD(	OBJ_LINE_TO_T3dPOINT(VE->Strings[b-1]	))+");");

//obj->Add("glTexCoord2f("+TEXTPOINT_TO_BGLCMD(	OBJ_LINE_TO_TEXTPOINT(VE->Strings[cuv-1]	))+");");
obj->Add("glVertex3f("+POINT_TO_BGLCMD(	OBJ_LINE_TO_T3dPOINT(VE->Strings[c-1]	))+");");

//VBO_BE[fcnt].INDEX_START



obj->Add("end;");       				}



	 }









}


AnsiString result=            ExtractFilePath(filename);
obj->SaveToFile(result+"PYK2.TXT");
MATERIAL_FILE->SaveToFile(result+"PYK2.MATT");


delete MATERIAL_FILE;
//vt 7.850000 -6.686250

LoadFromBGLCMD(obj);
delete obj;
int texcount = -1;

	   for (i = 0; i < k->Count; i++)
		if (Pos("vt",LowerCase(k->Strings[i])) > 0) {
	   s = k->Strings[i];
get_all_in_nawias(s, " ",4);
				 texcount = texcount + 1;
VBO_T[texcount].x = pstrtofloat(w_nawiasie[4][1]);
VBO_T[texcount].y = pstrtofloat(w_nawiasie[4][2]);



	   }

delete k;

SaveModel(result+"PYK2.tachogl",false);
SaveToBGLCMD(result+"PYK_BGLCMD.TXT",false);
}




 

 

 

this is the present code now it uses one librarty that i have written long time ago in object pascal but i have it on my broken notebook, and i dont have time to show you this unit: 

one thing is that

get_all_in_nawias(s, " ",4); is a  function that separates string into an array (the splitter is in this case " ")

'

 

but i looked into this more modern code and found some steps you want to make:

 

count vertices and faces, then you gather face info and match corresponding vertices to it, its all there

0

Share this post


Link to post
Share on other sites

First of all, just to make sure: remember that indices in OBJ models start counting from 1, not from 0. Yes, this catches off-guard pretty much everybody who attempts to make an OBJ parser. I didn't take a close look at the code so I may have missed something but it didn't seem like you were accounting for that.

 

EDIT: nevermind it seems like you handle that at the end, unless I misunderstood something.

Edited by Sik_the_hedgehog
0

Share this post


Link to post
Share on other sites

I replaced drawElement with drawArrays, and it draws the cube perfectly, so the problem is with the indices.

Edited by RobeeZ
0

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
Sign in to follow this  
Followers 0