dev.gamez.lv Forum Index dev.gamez.lv
Latvian Game Developers Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups 

Nolasīt un parādīt obj failu bez ģeometrijas kļūdām
Goto page Previous  1, 2, 3, 4  Next
 
dev.gamez.lv Forum Index -> OpenGL
View previous topic :: View next topic  
Author Message
Storm



Joined: 11 Apr 2006
Posts: 742

PostPosted: Tue Sep 08, 2009 12:18 am    Post subject:

9 manupraat neliek uint. Videokartes pasas par sevi nekaadus uber vertex indeksus neatbalsta. Kaads sakars fail. Vienkaarsi unsigned rada probleemas dazaas valodaas jo nepieciesams casts ja veelies atnjemt vai arii jaalieto speciaalas notaacijas.
_________________
Izraadaas ka dazu dev.gamez.lv lietotaaju absurdaa ignorance meedz eksisteet arii augstaakas paakaapees : http://www.gamedev.net/community/forums/topic.asp?topic_id=411552
Back to top
View user's profile
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Tue Sep 08, 2009 1:33 am    Post subject:

e, kādas problēmas? unsigned jau by default ir hardwarē, kā mašīnkodu tips atbalstīts (daudzum-daudzām arhitektūrām). Neesmu saskāries ne ar kādām problēmām. Tā ir valodas problēma, ja neatbalsta unsigned tipu, ne tipa problēma. Un drīzāk otrādi - signed int'u tips tieši ir viens liels haks skaitļa glabāšanā atmiņā/reģistros (two's complement form, atšķirībā no normāla float'u glabāšanas ar zīmes bitu). Unsigned skaitļa pieraksts bināri ir visdabiskākais kāds iespējams.

Saki 9 ir signed? Es tev neticu, un esmu par 100% pārliecināts, ka tur ir unsigned. Ieliec -2 16-bitu indeksu masīvā un paskaties, kas notiks. Varu derēt, ka tiks paņemts 65534-tais elements, nevis krašs/nedefinēts-rezultāts dēļ tā, ka tiks ņemts 2 elements pirms vertex buffer sākuma.

Nav nekādi ūber vertex indeksi jāatbalsta, ja GL_UNSIGNED_BYTE un GL_UNSIGNED_SHORT tipiem ir ļoti normālas indeksu vērtības no 128 līdz 255 un no 32768 līdz 65536 attiecīgi.

Fail tāpēc, ka citiem pārmet kaut ko, ko viņš nezin ("Bet tas ir fascineejoshi ka pat sito nejeedz- tas ir - copy paste ...", utml), taču pats arī aplamības runā.
Back to top
View user's profile Send e-mail
Vecis



Joined: 01 Jan 2007
Posts: 144

PostPosted: Tue Sep 08, 2009 5:39 pm    Post subject:

Code:

import appuifw, key_codes, glcanvas, graphics, e32
from gles import *


verts=[]
tris=[]

def load_obj():
 global verts, tris
 a=[]
 obj_file = file("E:\obj1.obj")
 obj_file.seek(0)
 for line in obj_file:
  a=line.split()
  if a != []:
   cmd=a[0]
   param=a[1:]
   if cmd != "#" or cmd != "object" or cmd != "mtllib" or cmd != "g" or cmd != "usemtl":
    if cmd=="v":
     verts.append(param)
    elif cmd=="f":
     tris.append(param)
load_obj()

lverts=[]
ltris=[]
def add_verts(list):
 temp=[]
 for x, y, z in verts:
  temp.append(float(x))
  temp.append(float(y))
  temp.append(float(z))
  list.append(temp)
  temp=[]
add_verts(lverts)

def add_tris(list):
 temp=[]
 for i1, i2, i3 in tris:
  temp.append(int(i1)-1)
  temp.append(int(i2)-1)
  temp.append(int(i3)-1)
  list.append(temp)
  temp=[]

add_tris(ltris)



WHITE = (255,255,255)
 

def make_a_textur():
    global img1,size1
    img1 = graphics.Image.new((64,64))
    img1.clear(WHITE)
    size1=img1.size


vertices = array(GL_FIXED, 3, lverts)


triangles = array(GL_FIXED, 3, ltris)


texcoords = array(GL_BYTE, 2, [
    -1,-1,
    0,-1,
    0,0,
    -1,0])


def resize():
    #Resize handler
    glViewport(0, 0, canvas.size[0], canvas.size[1])
    aspect = float(canvas.size[1]) / float(canvas.size[0])
    glMatrixMode( GL_PROJECTION )
    glLoadIdentity()
    glFrustumf( -1.0, 1.0, -1.0*aspect, 1.0*aspect, 3.0, 1000.0 )




def initgl():
    global render
    #Initializes OpenGL and sets up the rendering environment

    #creating texture
    texture=glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, texture)
   
    glClearColorx(0,0,0,65536)# Set the screen background color.
    glEnable( GL_CULL_FACE  )# Enable back face culling.
    glEnable( GL_TEXTURE_2D )# Enable texture2D
    resize()# our function we made above
    glTexCoordPointerb(texcoords)# the pointer to our texture coordiates
    glMatrixMode( GL_MODELVIEW )
    glEnableClientState( GL_VERTEX_ARRAY )# Enable vertex arrays.
    glVertexPointerb(vertices)# Set array pointers.
    glEnableClientState(GL_TEXTURE_COORD_ARRAY)
    #glShadeModel( GL_SMOOTH )# smooth looks nice with low quality textures
    glShadeModel( GL_FLAT )# Set the initial shading mode
    glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST )# no perspective correction



def redraw(frame):
    global running,img1,size1
    iFrame = frame
    cameraDistance = 1000
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )
    if running:
        glPushMatrix()
        glMatrixMode( GL_TEXTURE )
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, size1[0], size1[1], 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, img1)


        glTexEnvx( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE )

        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR )
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR )

        glLoadIdentity()
        glMatrixMode( GL_MODELVIEW )
        glLoadIdentity()
        glTranslatef( 0 , 0  , -cameraDistance << 16)
        glRotatef( iFrame << 16,1 << 16,0,0)
        glScalef( 2, 2, 2 )
        glDrawElementsub( GL_TRIANGLES, triangles )
        glPopMatrix()




def set_exit():
    global running, canvas
    canvas=None


make_a_textur()


running = 1
appuifw.app.exit_key_handler=set_exit
appuifw.app.screen = 'full'
canvas=glcanvas.GLCanvas(redraw_callback=redraw, event_callback=None, resize_callback=resize)
appuifw.app.body=canvas


initgl()

while running:
    canvas.drawNow()
    e32.ao_sleep(0.01)

Nu izmēģināju šādu variantu, nav ģeometrijas kļūdu, bet modeli vienkārši nerāda. Confused
Back to top
View user's profile Send e-mail
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Tue Sep 08, 2009 7:45 pm    Post subject:

Tu joprojām jauc x ar f kopā (piem: GL_FIXED un glRotatef/glTranslatef..).
Vertex masīva taisīšanā tu izmanto array(GL_FIXED, ..) taču vertex pointeriem tu norādi BYTE tipu (glVertexPointerb). Tam tiešām tā jāstrādā? Es pats Pythonu + GLES nezinu, varbūt ka tur maģija apakšā notiekās un viss konvertējās pats. Bet pārliecinites vai tiešām tā ir.
Es jau prātīgāk izmantotu to tipu, no kura taisa masīvu. - ja izmanto float tipu, tad norādi GL_FLOAT un vertex pointeru norādi kā f tipu.

Vēl iesaku izsaukt glGetError() fju (un protams pārbaudīt tās rezultātu) pēc katra glXXX izsaukuma - tas uzreiz parādīs, kurā rindiņa nofeilo ar OpenGL kļūdu (nepareizi parametri, nepareizā vietā izsaukta fja, neatļauta fja, utml).
Back to top
View user's profile Send e-mail
Vecis



Joined: 01 Jan 2007
Posts: 144

PostPosted: Thu Sep 10, 2009 6:50 pm    Post subject:

Code:

vertices = array(GL_FLOAT, 3, lverts)

Code:

    glVertexPointerf(vertices)# Set array pointers.

Vienalga nerāda modeli, tukša bilde.

glGetError() saka ka funkcija nav definēta.
Back to top
View user's profile Send e-mail
snake5
Indago dalībnieks
Indago dalībnieks


Joined: 27 Jun 2007
Posts: 2590

PostPosted: Thu Sep 10, 2009 7:07 pm    Post subject:

EDIT: sorry, sajaucu linkus googlē :/
_________________
"There are two choices here: "looks good" and "realism"." -- Paul Nettle


Last edited by snake5 on Thu Sep 10, 2009 9:28 pm; edited 2 times in total
Back to top
View user's profile Visit poster's website
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Thu Sep 10, 2009 8:30 pm    Post subject:

snake5: Ja nezini par ko ir runa, varbūt labāk neraksti neko? Viņš nelieto pyopengl. Viņš lieto Symbiāņa OpenGL ES portu zem pythona.

pys60 dokumentācija saka, ka tev pašam glGetError nav jāizsauc. Tā vietā wraperis pats izmetīs gles.GLerror exceptionu (5.7.2 sadaļa). Tā ka ar šo problēmu nav.
Back to top
View user's profile Send e-mail
Vecis



Joined: 01 Jan 2007
Posts: 144

PostPosted: Fri Sep 11, 2009 3:01 pm    Post subject:

Nu vēl ir tas

line 130 in redraw
glPopMatrix()
gles.GLerror: Stack underflow [Errno 504]

Nebiju tam pievērsis uzmanību jo viss itkā strādāja kamēr nemēģināju kādus sarežģītākus modeļus likt iekšā...
Back to top
View user's profile Send e-mail
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Fri Sep 11, 2009 3:34 pm    Post subject:

Tas nozīmē, ka tu izsauc PopMatrix vairāk nekā PushMatrix. Katram Pop izsaukumam jāatbilst vienam Push izsaukumam. Ne vairāk un ne mazāk.
Back to top
View user's profile Send e-mail
Vecis



Joined: 01 Jan 2007
Posts: 144

PostPosted: Fri Sep 11, 2009 3:53 pm    Post subject:

Tur jau tikai 1 popmatrix un pushmatrix ir redraw funkcijā
Code:

    if running:
        glPushMatrix()
        glMatrixMode( GL_TEXTURE )
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, size1[0], size1[1], 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, img1)

#this past is very important !!!
        glTexEnvx( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE )
        # Mipmapping must be disabled for each texture if not used
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR )
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR )
#otherwise the texture don't get replaced !!!
        glLoadIdentity()
        glMatrixMode( GL_MODELVIEW )
        glLoadIdentity()
        glTranslatef( 0 , 0  , -cameraDistance << 16)
        glRotatef( iFrame << 16,1 << 16,0,0)
        glScalef( 2, 2, 2 )
        glDrawElementsub( GL_TRIANGLES, triangles )
        glPopMatrix()
Back to top
View user's profile Send e-mail
snake5
Indago dalībnieks
Indago dalībnieks


Joined: 27 Jun 2007
Posts: 2590

PostPosted: Fri Sep 11, 2009 4:00 pm    Post subject:

Joks ir tāds, ka tie popmatrix un pushmatrix ir dažādās matrix mode.
P.S. Kāpēc tev vajag katru kadru uzstādīt tādu pašu GL_TEXTURE matricu?
_________________
"There are two choices here: "looks good" and "realism"." -- Paul Nettle
Back to top
View user's profile Visit poster's website
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Fri Sep 11, 2009 4:07 pm    Post subject:

Vecis wrote:
glTranslatef( 0 , 0 , -cameraDistance << 16)
glRotatef( iFrame << 16,1 << 16,0,0)

Es ceru, ka tu saproti, ka šīs rindiņas pareizina skaitļus cameraDistance, iFrame un 1 ar 65536 (=1<<16) pirms padot OpenGL'am. T.i, ja tev cameraDistance = 3, tad īstenībā translēšana notiek par 196608 vienībām. Tas pats ar rotāciju.
Back to top
View user's profile Send e-mail
Vecis



Joined: 01 Jan 2007
Posts: 144

PostPosted: Fri Sep 11, 2009 7:11 pm    Post subject:

Dabūju visu gatavu, pie vertices array liku GL_FLOAT
vertex pointeri liku uz f, tāpat arī pārējās funkcijas un ņēmu vērā pēdēju bubu postu un viss notiek, ģeometrija pareizi ielādējas tagad jāķerās klāt tekstūru koordinātām.
Ak jā, kam īsti ir domātas normāles (normals)?
Back to top
View user's profile Send e-mail
snake5
Indago dalībnieks
Indago dalībnieks


Joined: 27 Jun 2007
Posts: 2590

PostPosted: Fri Sep 11, 2009 7:21 pm    Post subject:

Tos parasti lieto apgaismojuma rēķināšanai. Bet var panākt ar šeideriem arī daudz citus interesantus efektus (šaubos gan, vai uz GLES tos vispār var lietot..).
_________________
"There are two choices here: "looks good" and "realism"." -- Paul Nettle
Back to top
View user's profile Visit poster's website
Vecis



Joined: 01 Jan 2007
Posts: 144

PostPosted: Fri Sep 11, 2009 7:31 pm    Post subject:

GLES kā tāds var, bet tikai jaunākajās trubās (SE Satio, Samsung Omnia HD, iPhone 3GS), vajag OpenGL 2.0, bet man te ir 1.1.
Back to top
View user's profile Send e-mail
Display posts from previous:   
dev.gamez.lv Forum Index -> OpenGL All times are GMT + 2 Hours
Goto page Previous  1, 2, 3, 4  Next
Page 2 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group