Results 1 to 4 of 4

Thread: opengl to opengl es

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2011
    Posts
    13

    opengl to opengl es

    Got an opengl code that I am trying to run on ios (opengl es).
    According to the visual output -- on windows (opengl) it works perfectly, whereas on ios (opengl es) there seems to be something wrong with the normals -- cause the visual presentation is faulty.

    Are there any initial parameters that are different on opengl and opengles?
    If so please let me know what I should change in order for the opengles to work properly?

    Here is the code I have used:

    To Initialize the opengl (code is written in delphi):
    Code :
      glShadeModel(GL_SMOOTH);                 // Enables Smooth Color Shading
    //**!!  glClearDepth(1.0);                       // Depth Buffer Setup
      glEnable(GL_DEPTH_TEST);                 // Enable Depth Buffer
      glDepthFunc(GL_LEQUAL);                    // The Type Of Depth Test To Do
      glBlendFunc(GL_SRC_ALPHA, GL_ONE);
      gldisable(GL_BLEND);
      glDisable(GL_TEXTURE_2D);
      glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);   //Realy Nice perspective calculations
     
      glEnable(GL_LIGHTING);
      glEnable(GL_COLOR_MATERIAL);
     
      if Model.NumLights = 0 then
      begin
     
      glEnable(GL_LIGHT0);
      glEnable(GL_LIGHT1);
     
      L1 := Make( 1,  5,  -3, 0); //Light position in world
      glLightfv(gl_light0, GL_POSITION, @L1);
     
      L1 := Make(1  , 1 , 1 , 1); //Light colour
      glLightfv(gl_light0, GL_DIFFUSE, @L1);
      glLightfv(gl_light0, GL_SPECULAR, @L1);
     
      L1 := Make( 1, -5, 0, 0); //Light position in world
      glLightfv(gl_light1, GL_POSITION, @L1);
     
      L1 := Make(1  ,0.5  , 0  , 1); //Light colour
      glLightfv(gl_light1, GL_DIFFUSE, @L1);
      glLightfv(gl_light1, GL_SPECULAR, @L1);
     
      end
      else
      begin
     
        for I := 0 to Max(7, Model.NumLights-1) do
        begin
         glEnable(GL_LIGHT0+I);
     
         L1 := Make(Model.Lights[I].P[0],  Model.Lights[I].P[1],  Model.Lights[I].P[2], 0); //Light position in world
         glLightfv(gl_light0+I, GL_POSITION, @L1);
     
         L1 := Make(Model.Lights[I].R, Model.Lights[I].G , Model.Lights[I].B , 1); //Light colour
         glLightfv(gl_light0+I, GL_DIFFUSE, @L1);
         glLightfv(gl_light0+I, GL_SPECULAR, @L1);
     
        end;
      end;
     
      L1 := Make(1  , 1  , 1  , 0); //Light colour
      glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, @L1);
     
      Sh := 50;
      glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, @Sh);
    //**!!  glLightmodeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
    end;

    To draw the data to screen:
    Code :
    type
      Verticies = array [0..2] of word;
    Var I, J, z, Face: integer;
      MV: array of Verticies;
      dataV, dataN: array of Vertex3ds;
    begin
      glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);    // Clear The Screen And The Depth Buffer
      glLoadIdentity();
     
      glTranslatef(0,0,Cz);
      glRotatef(Cx, 1, 0, 0);
      glRotatef(Cy, 0, 1, 0);
     
      glBindtexture(GL_TEXTURE_2D, tex);
     
      z := 0;
      SetLength(MV, NumFaces);
      SetLength(dataV, (NumFaces+1)*3);
      SetLength(dataN, (NumFaces+1)*3);
      FOR I:=0 to NumFaces-1 do
        For J := 0 to 2 do
        begin
          dataV[z] := V[F[I][J]];
          dataN[z] := N[nF[I][J]];
          MV[I][J] := z;
          inc(z);
        end;
     
      glEnableClientState(GL_NORMAL_ARRAY);
      glEnableClientState(GL_VERTEX_ARRAY);
      glNormalPointer(GL_FLOAT, 0, @dataN[0]); //@anormal[0][0][0]);
      glVertexPointer(3, GL_FLOAT,0, @dataV[0] ); //@avertex[0][0][0]);
      glDrawElements(GL_TRIANGLES,(NumFaces-1)*3,GL_UNSIGNED_SHORT, @MV[0]);
      glDisableClientState(GL_VERTEX_ARRAY);  // disable vertex arrays
     
    //  glDrawElements(GL_TRIANGLES,(NumFaces-1)*3,GL_UNSIGNED_SHORT, @nF[0]);
      glDisableClientState(GL_NORMAL_ARRAY);
     
      SetLength(MV, 0);
      SetLength(dataV, 0);
      SetLength(dataN, 0);

    Same code is being used both on windows (opengl), and on ios (opengles v1.1).

  2. #2
    Junior Member Newbie
    Join Date
    Feb 2011
    Posts
    13

    Re: opengl to opengl es

    here is a sample of the result I get on both platforms:
    http://bueno.co.il/test

  3. #3
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896

    Re: opengl to opengl es

    From the images it looks as if depth testing is not enabled or the resolution of the depth buffer is insufficient (possibly due to badly chose near/far values?) - e.g. the driver side rear tire is drawn on top of the car body geometry.
    Do you request a depth buffer when creating your application framebuffer/OpenGL context?

  4. #4
    Junior Member Newbie
    Join Date
    Feb 2011
    Posts
    13

    Re: opengl to opengl es

    Thanks that was the depthBuffer that I needed.
    Now it is working properly.

Similar Threads

  1. Replies: 3
    Last Post: 12-22-2015, 09:48 PM
  2. Replies: 3
    Last Post: 07-09-2014, 07:19 AM
  3. OpenGL, OpenGL extensions and OpenGL shading language?
    By rakeshthp in forum OpenGL: Windows
    Replies: 4
    Last Post: 05-06-2012, 11:11 AM
  4. Replies: 4
    Last Post: 08-04-2004, 08:54 PM
  5. Replies: 2
    Last Post: 09-06-2000, 11:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean