Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (777)
Games in Android Showcase (231)
games submitted by our members
Games in WIP (856)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Problem with GL_SMOOTH  (Read 5519 times)
0 Members and 1 Guest are viewing this topic.
Offline vinodpatel2006

Junior Devvie





« Posted 2007-09-27 09:59:12 »

Hello,

           I am facing a problem with GL_SMOOTH shade model and polygon mode GL_LINE.

           The problem is that when i render polygon data using
                                           
                                       m_gl.glShadeModel(GL.GL_FLAT);

            it works fine but if i render same data using

                                    m_gl.glShadeModel(GL.GL_SMOOTH);
           it does not appears on the screen. I mean, i am not able to draw anything on the screen.
          I have set polygon mode like this
               m_gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE); for wireframe display of objects.

         if i set polygon mode like this
             m_gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL); it works fine for all cases.


         What could be a problem?, i am very frustrated about this problem.
        Any help would be appreciated.

Thanks In Advance
         
Offline flipperke

Junior Devvie





« Reply #1 - Posted 2007-09-27 15:31:28 »

Is that the only line of code that you change?
Can you give an example of code where your'e facing that problem?
Offline lhkbob

JGO Knight


Medals: 32



« Reply #2 - Posted 2007-09-27 18:04:44 »

Are you saying that nothing shows up when you have the polygon mode set to GL_LINE AND shade mode set to GL_SMOOTH

or

if GL_SMOOTH is set, nothing shows up regardless of whether or not polygon mode is GL_LINE or GL_FILL?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline vinodpatel2006

Junior Devvie





« Reply #3 - Posted 2007-09-28 04:11:31 »

Hello,

        Second one is correct,

         
                 if GL_SMOOTH is set, nothing shows up regardless of whether or not polygon mode is GL_LINE or GL_FILL?

Regards
Offline Jark

Senior Newbie





« Reply #4 - Posted 2007-09-28 07:12:15 »

Hey,

Are you using lights in your code? And are you using materials and/or normals? And if not how are you setting the color?
I tried setting my shademodel to GL_SMOOTH and it works perfectly in my case.

You can read more about opengl and lights here --> http://www.opengl.org/resources/faq/technical/lights.htm
Offline vinodpatel2006

Junior Devvie





« Reply #5 - Posted 2007-09-28 07:46:45 »

Hello,

            I am using both material and Lights in my code. The problem is that same data render in different ways when i use GL_FLAT  and GL_SMOOTH.

          For Example, if i render using  GL_SMOOTH, it will render correct but if i use GL_FLAT, it ploats some vertex at different location. It completly change shape and size of the object.

Regards
Offline flipperke

Junior Devvie





« Reply #6 - Posted 2007-09-28 08:52:28 »

Try to disable light and material, see if that changes anything (except the light and material of course).
Offline vinodpatel2006

Junior Devvie





« Reply #7 - Posted 2007-09-28 09:23:16 »

Hello,

           I tried it but not gettting any success. I think that light and material could not be a problem because if i disable light and material, it renders in black color.

           I could not understand why it changes position of the vertex when i change shade model?

Regards
Offline flipperke

Junior Devvie





« Reply #8 - Posted 2007-09-28 10:09:31 »

Maybe, you could show your init and display code...
It's very strange that vertices move when you change shade model?
Offline vinodpatel2006

Junior Devvie





« Reply #9 - Posted 2007-09-28 10:21:37 »

Hello,


             Initialization Code
            =============================================================
      // Initialize rendering context
      m_gl.glEnable(GL.GL_CULL_FACE);
      m_gl.glEnable(GL.GL_DEPTH_TEST);
      m_gl.glShadeModel(GL.GL_SMOOTH);
      m_gl.glDepthFunc(GL.GL_LESS);
      m_gl.glClearDepth(1);
      m_gl.glClearColor(0, 0, 0, 0);

      // Alpha
      m_gl.glDisable(GL.GL_BLEND);
      m_gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);

      // Lights
      for (int Jcount = GL.GL_LIGHT0; Jcount <= GL.GL_LIGHT7; Jcount++) {
         m_gl.glDisable(Jcount);
      }

      m_gl.glEnable(GL.GL_LIGHTING);
      m_gl.glFrontFace(GL.GL_CW);
      m_gl.glLightModeli(GL.GL_LIGHT_MODEL_LOCAL_VIEWER, 1);

      m_DebugFontHeight = 16;
      if (m_DeviceContext == null) {
      }

      m_Texturing = false;
      m_GenerateTexCoords = false;
      m_EnvMapOn = false;
      m_NormalizeNormals = false;

      m_ViewMatrix.setIdentity();
      m_WorldMatrix.setIdentity();

      endRendererContext();

      setActive(true);
      setRendererType("OpenGL");
      setRendererSubType("");
      return QEDResponseCode.Q3D_RENDERER_OK;

           rendering code
         ---------------------------------------------------------------------------------------

      try{
         if (m_Texturing && m_EnvMapOn && normals != null) {
            CQ3DMatrix worldview = new CQ3DMatrix();
            worldview.mul(m_ViewMatrix, m_WorldMatrix);
            for (int i = 0, face = 0; i < nbIndex; i += 3, face++) {
               CQ3DVector normal = new CQ3DVector();
   
               normal.assign(normals[face]);
               normal.transformNoTrans(worldview);
   
               if (m_NormalizeNormals) {
                  normal.normalize(); // Maybe a scale Huh
               }
   
               float UV[] = new float[2];
   
               UV[0] = normal.m_Vector.x * 0.5f + 0.5f;
               UV[1] = normal.m_Vector.y * 0.5f + 0.5f;
   
               float norm[] = new float[3];
               norm[0] = normals[face].x;
               norm[1] = normals[face].y;
               norm[2] = normals[face].z;
   
               m_gl.glBegin(GL.GL_TRIANGLES);
               m_gl.glNormal3fv(norm, 0);
               m_gl.glTexCoord3fv(UV, 0);
               norm[0] = vertices[faces[face + faceindex].a].pos.x;
               norm[1] = 0;
               norm[2] = 0;
               m_gl.glVertex3fv(norm, 0);
               norm[0] = vertices[faces[face + faceindex].b].pos.x;
               m_gl.glVertex3fv(norm, 0);
               norm[0] = vertices[faces[face + faceindex].c].pos.x;
               m_gl.glVertex3fv(norm, 0);
               m_gl.glEnd();
            }
            return QEDResponseCode.Q3D_RENDERER_OK;
         }
   
         SQ3DVERTEX[] Vertices = prepareVertices(vertices, nbVertices);
         m_gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
         
         //FloatBuffer buffer = BufferUtil.newFloatBuffer(Vertices.length * 2);
         FloatBuffer buffer = getFloatBuffer((int)nbVertices*2,1);
         
         if (m_Texturing && !m_GenerateTexCoords) {
            m_gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY);
            for (int Icount = 0; Icount < nbVertices; Icount++) {
               buffer.put(Vertices[Icount].u);
               buffer.put(Vertices[Icount].v);
            }
            buffer.rewind();
            m_gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, buffer);
         } else {
            m_gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY);
         }
         
         //buffer = BufferUtil.newFloatBuffer(Vertices.length * 3);
         buffer = getFloatBuffer((int)nbVertices*3,2);
         
         for (int Icount = 0; Icount < nbVertices; Icount++) {
            buffer.put(Vertices[Icount].pos.x);
            buffer.put(Vertices[Icount].pos.y);
            buffer.put(Vertices[Icount].pos.z);
         }
         buffer.rewind();
         m_gl.glVertexPointer(3, GL.GL_FLOAT, 0, buffer);
         
         if (normals == null){
            m_gl.glEnableClientState(GL.GL_NORMAL_ARRAY);         
            
            //buffer = BufferUtil.newFloatBuffer(Vertices.length*3);
            buffer = getFloatBuffer((int)nbVertices*3,3);
            
            for (int Icount = 0; Icount < nbVertices; Icount++) {
               buffer.put(Vertices[Icount].normal.x);
               buffer.put(Vertices[Icount].normal.y);
               buffer.put(Vertices[Icount].normal.z);
            }
            buffer.rewind();
            m_gl.glNormalPointer(GL.GL_FLOAT, 0, buffer);
   
            //ShortBuffer shBuf = BufferUtil.newShortBuffer(faces.length * 3);
            ShortBuffer shBuf = getShortBuffer(faces.length * 3);
            for (int Icount = faceindex; Icount < faces.length; Icount++) {
               shBuf.put((short) faces[Icount].a);
               shBuf.put((short) faces[Icount].b);
               shBuf.put((short) faces[Icount].c);
            }
            shBuf.rewind();
   
            m_gl.glDrawElements(GL.GL_TRIANGLES, (int) nbIndex,GL.GL_UNSIGNED_SHORT, shBuf);
            m_gl.glDisableClientState(GL.GL_NORMAL_ARRAY);
         } else {
            m_gl.glDisableClientState(GL.GL_NORMAL_ARRAY);
            m_gl.glBegin(GL.GL_TRIANGLES);
            for (int i = 0, face = 0; i < nbIndex; i += 3) {
               buffer.put(0, normals[face].x);
               buffer.put(1, normals[face].y);
               buffer.put(2, normals[face].z);
               m_gl.glNormal3fv(buffer);
               m_gl.glArrayElement(faces[face + faceindex].a);
               m_gl.glArrayElement(faces[face + faceindex].b);
               m_gl.glArrayElement(faces[face + faceindex].c);
               face++;
            }
            m_gl.glEnd();
            m_gl.glEnableClientState(GL.GL_NORMAL_ARRAY);
         }
   
         m_gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
   
         if (m_Texturing && !m_GenerateTexCoords) {
            m_gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY);
         }
      }
      catch(NullPointerException e){
         logger.error("Vertices object =" + vertices);
         logger.error("Normals object =" + normals);
         logger.error("Faces object =" + faces);
      }
      return QEDResponseCode.Q3D_RENDERER_OK;


        Renderer state method code
-----------------------------------------------


      switch ((int) state)
      {
         case QEDConstantCode.Q3DRENDERSTATE_ZTESTENABLE:
         {
            if (value > 0){
               m_gl.glEnable(GL.GL_DEPTH_TEST);
            }
            else{
               m_gl.glDisable(GL.GL_DEPTH_TEST);
            }
         }
         break;
         case QEDConstantCode.Q3DRENDERSTATE_ZWRITEENABLE:
         {
            if (value > 0)
               m_gl.glDepthMask(true);
            else
               m_gl.glDepthMask(false);
         }
         break;
         case QEDConstantCode.Q3DRENDERSTATE_COLORWRITEENABLE:
         {
            if (value > 0)
               m_gl.glColorMask(true, true, true, true);
            else
               m_gl.glColorMask(false, false, false, false);
         }
         break;
         case QEDConstantCode.Q3DRENDERSTATE_FILLMODE:
         {
            switch ((int) value)
            {
               case QEDConstantCode.Q3DFILL_WIREFRAME:
                  m_gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);
                  m_gl.glDisable(GL.GL_POLYGON_SMOOTH);
                  break;
               case QEDConstantCode.Q3DFILL_SOLID:
                  m_gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);
                  break;
            }
         }
            break;
         case QEDConstantCode.Q3DRENDERSTATE_SHADEMODE:
         {
            switch ((int) value)
            {
               case QEDConstantCode.Q3DSHADE_FLAT:
               {
                  m_gl.glShadeModel(GL.GL_FLAT);
               }
               break;
               case QEDConstantCode.Q3DSHADE_GOURAUD:
               {
                  m_gl.glShadeModel(GL.GL_SMOOTH);
               }
               break;
            }
         }
         break;

         case QEDConstantCode.Q3DRENDERSTATE_SPECULARENABLE: {}
         break;
         case QEDConstantCode.Q3DRENDERSTATE_AMBIENT:
         {
            float tab[] = new float[4];
   
            tab[0] = ((float) ((value >> 16) & 0xFF)) / 255.0f;
            tab[1] = ((float) ((value >> Cool & 0xFF)) / 255.0f;
            tab[2] = ((float) ((value) & 0xFF)) / 255.0f;
            tab[3] = ((float) ((value >> 24) & 0xFF)) / 255.0f;
   
            m_gl.glEnable(GL.GL_LIGHTING);
            m_gl.glLightModelfv(GL.GL_LIGHT_MODEL_AMBIENT, FloatBuffer.wrap(tab));
         }
         break;
         case QEDConstantCode.Q3DRENDERSTATE_CULLMODE:
         {
            switch ((int) value)
            {
               case QEDConstantCode.Q3DCULL_NONE:
               {
                  m_gl.glDisable(GL.GL_CULL_FACE);
               }
               break;
               case QEDConstantCode.Q3DCULL_CCW:
               {
                  m_gl.glFrontFace(GL.GL_CW);
                  m_gl.glCullFace(GL.GL_BACK);
                  m_gl.glEnable(GL.GL_CULL_FACE);
               }
               break;
               case QEDConstantCode.Q3DCULL_CW:
               {
                  m_gl.glFrontFace(GL.GL_CCW);
                  m_gl.glCullFace(GL.GL_BACK);
                  m_gl.glEnable(GL.GL_CULL_FACE);
               }
               break;
            }
         }
            break;
         case QEDConstantCode.Q3DRENDERSTATE_TWOSIDED:
         {
            m_gl.glLightModeli(GL.GL_LIGHT_MODEL_TWO_SIDE, (int) value);
         }
         break;
         case QEDConstantCode.Q3DRENDERSTATE_LIGHTING:
         {
            if (value > 0){
               m_gl.glEnable(GL.GL_LIGHTING);
            }
            else{
               m_gl.glDisable(GL.GL_LIGHTING);
            }
         }
         break;
         case QEDConstantCode.Q3DRENDERSTATE_COLORVERTEX: {}
         break;
         case QEDConstantCode.Q3DRENDERSTATE_NORMALIZENORMALS:
         {
            if (value > 0) {
               m_gl.glEnable(GL.GL_NORMALIZE);
               m_NormalizeNormals = true;
            } else {
               m_gl.glDisable(GL.GL_NORMALIZE);
               m_NormalizeNormals = false;
            }
         }
         break;
         case QEDConstantCode.Q3DRENDERSTATE_ALPHABLENDENABLE:
         {
            if (value > 0) {
               m_gl.glEnable(GL.GL_BLEND);
               m_gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
               m_gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE,GL.GL_MODULATE);
            }else{
               m_gl.glDisable(GL.GL_BLEND);
               m_gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE,GL.GL_MODULATE);
            }
         }
         break;
      }


Regards
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline flipperke

Junior Devvie





« Reply #10 - Posted 2007-09-28 10:34:57 »

mmmh..., okay...
I see why you didn't post your code earlier.
This goes way beyond my knowledge of Jogl or OpenGL, I fear someone else will have to help you.
Sorry
Offline vinodpatel2006

Junior Devvie





« Reply #11 - Posted 2007-09-28 10:39:22 »

Hello,

          Ok, no problem. Thank Very Much You for your kind help.

Regards
Offline lhkbob

JGO Knight


Medals: 32



« Reply #12 - Posted 2007-09-29 00:11:43 »

Try making a simple test case without all of the additional work thrown in that you have right now.  If there's still a problem then it could be something wrong with your drivers.

Offline vinodpatel2006

Junior Devvie





« Reply #13 - Posted 2007-09-29 03:53:18 »

Hello  lhkbob,
 
             I have tried using the small program but again same. I could not understand why same data plot differently when i use GL_LINE,  GL_FILL and GL_SMOOTH. I keep same data for both cases but for one case it ploat correctly and for other it changes position of the some vertex.

Regards
Pages: [1]
  ignore  |  Print  
 
 

 
hadezbladez (336 views)
2018-11-16 13:46:03

hadezbladez (180 views)
2018-11-16 13:41:33

hadezbladez (336 views)
2018-11-16 13:35:35

hadezbladez (83 views)
2018-11-16 13:32:03

EgonOlsen (2177 views)
2018-06-10 19:43:48

EgonOlsen (2205 views)
2018-06-10 19:43:44

EgonOlsen (1378 views)
2018-06-10 19:43:20

DesertCoockie (2009 views)
2018-05-13 18:23:11

nelsongames (1654 views)
2018-04-24 18:15:36

nelsongames (2299 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!