Stop GL_TRIANGLE_STRIP from connecting last and first vertex?












2














I have been trying to build a Terrain Visualizer from OpenGL and using a height map from simplex noise. I have the generator all sorted and it produces both colored and non-colored images, I only want to visualized the colored ones. However there is this weird bump thing, that I believe is a result of GL_TRIANGLE_STRIP.



Picture of the artifact, oddities outlined in red:



Picture of the artifact



My best guess is GL_TRIANGLE_STRIP attaching the first and last vertex, but I do not know.



Here is my code:



import pyglet
from pyglet.gl import *
from pyglet.window import key
import math
from PIL import Image

class Model:
def get_points_in_list(self, fp):
img = Image.open(fp)
self.points = [[0 for x in range(img.width)] for y in range(img.height)]
for y in range(img.height):
for x in range(img.width):
self.points[y][x] = ((x, img.getpixel((x, y))[3], y), img.getpixel((x, y)))

def add_points_to_batch(self):
ysiz = len(self.points)
xsiz = len(self.points[0])
# color1[0], color1[1], color1[2], color2[0], color2[1], color2[2]
for yy in range(ysiz-1):
for xx in range(xsiz):
pos = self.points[yy][xx][0]
x, y, z = pos[0], pos[1], pos[2]
pos1 = self.points[yy+1][xx][0]
X, Y, Z = pos1[0], pos1[1], pos1[2]

color1 = (self.points[yy][xx][1][0], self.points[yy][xx][1][1], self.points[yy][xx][1][2])
color2 = (self.points[yy+1][xx][1][0], self.points[yy+1][xx][1][1], self.points[yy+1][xx][1][2])
self.batch.add(2, GL_TRIANGLE_STRIP, None,
('v3f', (x, y, z, X, Y, Z)),
('c3B', (color1[0], color1[1], color1[2], color2[0], color2[1], color2[2]))
)

def __init__(self):
self.batch = pyglet.graphics.Batch()
self.points = None
self.get_points_in_list('Output_colored.png')
self.add_points_to_batch()

def draw(self):
self.batch.draw()

class Player:
def __init__(self, pos=(0, 0, 0), rot=(0, 0)):
self.pos = list(pos)
self.rot = list(rot)

def mouse_motion(self, dx, dy):
dx /= 8
dy /= 8
self.rot[0] += dy
self.rot[1] -= dx
if self.rot[0]>90:
self.rot[0] = 90
elif self.rot[0] < -90:
self.rot[0] = -90

def update(self,dt,keys):
sens = 1
s = dt*100
rotY = -self.rot[1]/180*math.pi
dx, dz = s*math.sin(rotY), math.cos(rotY)
if keys[key.W]:
self.pos[0] += dx*sens
self.pos[2] -= dz*sens
if keys[key.S]:
self.pos[0] -= dx*sens
self.pos[2] += dz*sens
if keys[key.A]:
self.pos[0] -= dz*sens
self.pos[2] -= dx*sens
if keys[key.D]:
self.pos[0] += dz*sens
self.pos[2] += dx*sens
if keys[key.SPACE]:
self.pos[1] += s
if keys[key.LSHIFT]:
self.pos[1] -= s

class Window(pyglet.window.Window):

def push(self,pos,rot):
glPushMatrix()
rot = self.player.rot
pos = self.player.pos
glRotatef(-rot[0],1,0,0)
glRotatef(-rot[1],0,1,0)
glTranslatef(-pos[0], -pos[1], -pos[2])

def Projection(self):
glMatrixMode(GL_PROJECTION)
glLoadIdentity()

def Model(self):
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()

def set2d(self):
self.Projection()
gluPerspective(0, self.width, 0, self.height)
self.Model()

def set3d(self):
self.Projection()
gluPerspective(70, self.width/self.height, 0.05, 1000)
self.Model()

def setLock(self, state):
self.lock = state
self.set_exclusive_mouse(state)

lock = False
mouse_lock = property(lambda self:self.lock, setLock)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.set_minimum_size(300,200)
self.keys = key.KeyStateHandler()
self.push_handlers(self.keys)
pyglet.clock.schedule(self.update)

self.model = Model()
self.player = Player((0.5,1.5,1.5),(-30,0))

def on_mouse_motion(self,x,y,dx,dy):
if self.mouse_lock: self.player.mouse_motion(dx,dy)

def on_key_press(self, KEY, _MOD):
if KEY == key.ESCAPE:
self.close()
elif KEY == key.E:
self.mouse_lock = not self.mouse_lock

def update(self, dt):
self.player.update(dt, self.keys)

def on_draw(self):
self.clear()
self.set3d()
self.push(self.player.pos,self.player.rot)
self.model.draw()
glPopMatrix()

if __name__ == '__main__':
window = Window(width=400, height=300, caption='Terrain Viewer', resizable=True)
glClearColor(0, 0, 0, 1)
glEnable(GL_DEPTH_TEST)
pyglet.app.run()









share|improve this question





























    2














    I have been trying to build a Terrain Visualizer from OpenGL and using a height map from simplex noise. I have the generator all sorted and it produces both colored and non-colored images, I only want to visualized the colored ones. However there is this weird bump thing, that I believe is a result of GL_TRIANGLE_STRIP.



    Picture of the artifact, oddities outlined in red:



    Picture of the artifact



    My best guess is GL_TRIANGLE_STRIP attaching the first and last vertex, but I do not know.



    Here is my code:



    import pyglet
    from pyglet.gl import *
    from pyglet.window import key
    import math
    from PIL import Image

    class Model:
    def get_points_in_list(self, fp):
    img = Image.open(fp)
    self.points = [[0 for x in range(img.width)] for y in range(img.height)]
    for y in range(img.height):
    for x in range(img.width):
    self.points[y][x] = ((x, img.getpixel((x, y))[3], y), img.getpixel((x, y)))

    def add_points_to_batch(self):
    ysiz = len(self.points)
    xsiz = len(self.points[0])
    # color1[0], color1[1], color1[2], color2[0], color2[1], color2[2]
    for yy in range(ysiz-1):
    for xx in range(xsiz):
    pos = self.points[yy][xx][0]
    x, y, z = pos[0], pos[1], pos[2]
    pos1 = self.points[yy+1][xx][0]
    X, Y, Z = pos1[0], pos1[1], pos1[2]

    color1 = (self.points[yy][xx][1][0], self.points[yy][xx][1][1], self.points[yy][xx][1][2])
    color2 = (self.points[yy+1][xx][1][0], self.points[yy+1][xx][1][1], self.points[yy+1][xx][1][2])
    self.batch.add(2, GL_TRIANGLE_STRIP, None,
    ('v3f', (x, y, z, X, Y, Z)),
    ('c3B', (color1[0], color1[1], color1[2], color2[0], color2[1], color2[2]))
    )

    def __init__(self):
    self.batch = pyglet.graphics.Batch()
    self.points = None
    self.get_points_in_list('Output_colored.png')
    self.add_points_to_batch()

    def draw(self):
    self.batch.draw()

    class Player:
    def __init__(self, pos=(0, 0, 0), rot=(0, 0)):
    self.pos = list(pos)
    self.rot = list(rot)

    def mouse_motion(self, dx, dy):
    dx /= 8
    dy /= 8
    self.rot[0] += dy
    self.rot[1] -= dx
    if self.rot[0]>90:
    self.rot[0] = 90
    elif self.rot[0] < -90:
    self.rot[0] = -90

    def update(self,dt,keys):
    sens = 1
    s = dt*100
    rotY = -self.rot[1]/180*math.pi
    dx, dz = s*math.sin(rotY), math.cos(rotY)
    if keys[key.W]:
    self.pos[0] += dx*sens
    self.pos[2] -= dz*sens
    if keys[key.S]:
    self.pos[0] -= dx*sens
    self.pos[2] += dz*sens
    if keys[key.A]:
    self.pos[0] -= dz*sens
    self.pos[2] -= dx*sens
    if keys[key.D]:
    self.pos[0] += dz*sens
    self.pos[2] += dx*sens
    if keys[key.SPACE]:
    self.pos[1] += s
    if keys[key.LSHIFT]:
    self.pos[1] -= s

    class Window(pyglet.window.Window):

    def push(self,pos,rot):
    glPushMatrix()
    rot = self.player.rot
    pos = self.player.pos
    glRotatef(-rot[0],1,0,0)
    glRotatef(-rot[1],0,1,0)
    glTranslatef(-pos[0], -pos[1], -pos[2])

    def Projection(self):
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()

    def Model(self):
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()

    def set2d(self):
    self.Projection()
    gluPerspective(0, self.width, 0, self.height)
    self.Model()

    def set3d(self):
    self.Projection()
    gluPerspective(70, self.width/self.height, 0.05, 1000)
    self.Model()

    def setLock(self, state):
    self.lock = state
    self.set_exclusive_mouse(state)

    lock = False
    mouse_lock = property(lambda self:self.lock, setLock)

    def __init__(self, *args, **kwargs):
    super().__init__(*args, **kwargs)
    self.set_minimum_size(300,200)
    self.keys = key.KeyStateHandler()
    self.push_handlers(self.keys)
    pyglet.clock.schedule(self.update)

    self.model = Model()
    self.player = Player((0.5,1.5,1.5),(-30,0))

    def on_mouse_motion(self,x,y,dx,dy):
    if self.mouse_lock: self.player.mouse_motion(dx,dy)

    def on_key_press(self, KEY, _MOD):
    if KEY == key.ESCAPE:
    self.close()
    elif KEY == key.E:
    self.mouse_lock = not self.mouse_lock

    def update(self, dt):
    self.player.update(dt, self.keys)

    def on_draw(self):
    self.clear()
    self.set3d()
    self.push(self.player.pos,self.player.rot)
    self.model.draw()
    glPopMatrix()

    if __name__ == '__main__':
    window = Window(width=400, height=300, caption='Terrain Viewer', resizable=True)
    glClearColor(0, 0, 0, 1)
    glEnable(GL_DEPTH_TEST)
    pyglet.app.run()









    share|improve this question



























      2












      2








      2







      I have been trying to build a Terrain Visualizer from OpenGL and using a height map from simplex noise. I have the generator all sorted and it produces both colored and non-colored images, I only want to visualized the colored ones. However there is this weird bump thing, that I believe is a result of GL_TRIANGLE_STRIP.



      Picture of the artifact, oddities outlined in red:



      Picture of the artifact



      My best guess is GL_TRIANGLE_STRIP attaching the first and last vertex, but I do not know.



      Here is my code:



      import pyglet
      from pyglet.gl import *
      from pyglet.window import key
      import math
      from PIL import Image

      class Model:
      def get_points_in_list(self, fp):
      img = Image.open(fp)
      self.points = [[0 for x in range(img.width)] for y in range(img.height)]
      for y in range(img.height):
      for x in range(img.width):
      self.points[y][x] = ((x, img.getpixel((x, y))[3], y), img.getpixel((x, y)))

      def add_points_to_batch(self):
      ysiz = len(self.points)
      xsiz = len(self.points[0])
      # color1[0], color1[1], color1[2], color2[0], color2[1], color2[2]
      for yy in range(ysiz-1):
      for xx in range(xsiz):
      pos = self.points[yy][xx][0]
      x, y, z = pos[0], pos[1], pos[2]
      pos1 = self.points[yy+1][xx][0]
      X, Y, Z = pos1[0], pos1[1], pos1[2]

      color1 = (self.points[yy][xx][1][0], self.points[yy][xx][1][1], self.points[yy][xx][1][2])
      color2 = (self.points[yy+1][xx][1][0], self.points[yy+1][xx][1][1], self.points[yy+1][xx][1][2])
      self.batch.add(2, GL_TRIANGLE_STRIP, None,
      ('v3f', (x, y, z, X, Y, Z)),
      ('c3B', (color1[0], color1[1], color1[2], color2[0], color2[1], color2[2]))
      )

      def __init__(self):
      self.batch = pyglet.graphics.Batch()
      self.points = None
      self.get_points_in_list('Output_colored.png')
      self.add_points_to_batch()

      def draw(self):
      self.batch.draw()

      class Player:
      def __init__(self, pos=(0, 0, 0), rot=(0, 0)):
      self.pos = list(pos)
      self.rot = list(rot)

      def mouse_motion(self, dx, dy):
      dx /= 8
      dy /= 8
      self.rot[0] += dy
      self.rot[1] -= dx
      if self.rot[0]>90:
      self.rot[0] = 90
      elif self.rot[0] < -90:
      self.rot[0] = -90

      def update(self,dt,keys):
      sens = 1
      s = dt*100
      rotY = -self.rot[1]/180*math.pi
      dx, dz = s*math.sin(rotY), math.cos(rotY)
      if keys[key.W]:
      self.pos[0] += dx*sens
      self.pos[2] -= dz*sens
      if keys[key.S]:
      self.pos[0] -= dx*sens
      self.pos[2] += dz*sens
      if keys[key.A]:
      self.pos[0] -= dz*sens
      self.pos[2] -= dx*sens
      if keys[key.D]:
      self.pos[0] += dz*sens
      self.pos[2] += dx*sens
      if keys[key.SPACE]:
      self.pos[1] += s
      if keys[key.LSHIFT]:
      self.pos[1] -= s

      class Window(pyglet.window.Window):

      def push(self,pos,rot):
      glPushMatrix()
      rot = self.player.rot
      pos = self.player.pos
      glRotatef(-rot[0],1,0,0)
      glRotatef(-rot[1],0,1,0)
      glTranslatef(-pos[0], -pos[1], -pos[2])

      def Projection(self):
      glMatrixMode(GL_PROJECTION)
      glLoadIdentity()

      def Model(self):
      glMatrixMode(GL_MODELVIEW)
      glLoadIdentity()

      def set2d(self):
      self.Projection()
      gluPerspective(0, self.width, 0, self.height)
      self.Model()

      def set3d(self):
      self.Projection()
      gluPerspective(70, self.width/self.height, 0.05, 1000)
      self.Model()

      def setLock(self, state):
      self.lock = state
      self.set_exclusive_mouse(state)

      lock = False
      mouse_lock = property(lambda self:self.lock, setLock)

      def __init__(self, *args, **kwargs):
      super().__init__(*args, **kwargs)
      self.set_minimum_size(300,200)
      self.keys = key.KeyStateHandler()
      self.push_handlers(self.keys)
      pyglet.clock.schedule(self.update)

      self.model = Model()
      self.player = Player((0.5,1.5,1.5),(-30,0))

      def on_mouse_motion(self,x,y,dx,dy):
      if self.mouse_lock: self.player.mouse_motion(dx,dy)

      def on_key_press(self, KEY, _MOD):
      if KEY == key.ESCAPE:
      self.close()
      elif KEY == key.E:
      self.mouse_lock = not self.mouse_lock

      def update(self, dt):
      self.player.update(dt, self.keys)

      def on_draw(self):
      self.clear()
      self.set3d()
      self.push(self.player.pos,self.player.rot)
      self.model.draw()
      glPopMatrix()

      if __name__ == '__main__':
      window = Window(width=400, height=300, caption='Terrain Viewer', resizable=True)
      glClearColor(0, 0, 0, 1)
      glEnable(GL_DEPTH_TEST)
      pyglet.app.run()









      share|improve this question















      I have been trying to build a Terrain Visualizer from OpenGL and using a height map from simplex noise. I have the generator all sorted and it produces both colored and non-colored images, I only want to visualized the colored ones. However there is this weird bump thing, that I believe is a result of GL_TRIANGLE_STRIP.



      Picture of the artifact, oddities outlined in red:



      Picture of the artifact



      My best guess is GL_TRIANGLE_STRIP attaching the first and last vertex, but I do not know.



      Here is my code:



      import pyglet
      from pyglet.gl import *
      from pyglet.window import key
      import math
      from PIL import Image

      class Model:
      def get_points_in_list(self, fp):
      img = Image.open(fp)
      self.points = [[0 for x in range(img.width)] for y in range(img.height)]
      for y in range(img.height):
      for x in range(img.width):
      self.points[y][x] = ((x, img.getpixel((x, y))[3], y), img.getpixel((x, y)))

      def add_points_to_batch(self):
      ysiz = len(self.points)
      xsiz = len(self.points[0])
      # color1[0], color1[1], color1[2], color2[0], color2[1], color2[2]
      for yy in range(ysiz-1):
      for xx in range(xsiz):
      pos = self.points[yy][xx][0]
      x, y, z = pos[0], pos[1], pos[2]
      pos1 = self.points[yy+1][xx][0]
      X, Y, Z = pos1[0], pos1[1], pos1[2]

      color1 = (self.points[yy][xx][1][0], self.points[yy][xx][1][1], self.points[yy][xx][1][2])
      color2 = (self.points[yy+1][xx][1][0], self.points[yy+1][xx][1][1], self.points[yy+1][xx][1][2])
      self.batch.add(2, GL_TRIANGLE_STRIP, None,
      ('v3f', (x, y, z, X, Y, Z)),
      ('c3B', (color1[0], color1[1], color1[2], color2[0], color2[1], color2[2]))
      )

      def __init__(self):
      self.batch = pyglet.graphics.Batch()
      self.points = None
      self.get_points_in_list('Output_colored.png')
      self.add_points_to_batch()

      def draw(self):
      self.batch.draw()

      class Player:
      def __init__(self, pos=(0, 0, 0), rot=(0, 0)):
      self.pos = list(pos)
      self.rot = list(rot)

      def mouse_motion(self, dx, dy):
      dx /= 8
      dy /= 8
      self.rot[0] += dy
      self.rot[1] -= dx
      if self.rot[0]>90:
      self.rot[0] = 90
      elif self.rot[0] < -90:
      self.rot[0] = -90

      def update(self,dt,keys):
      sens = 1
      s = dt*100
      rotY = -self.rot[1]/180*math.pi
      dx, dz = s*math.sin(rotY), math.cos(rotY)
      if keys[key.W]:
      self.pos[0] += dx*sens
      self.pos[2] -= dz*sens
      if keys[key.S]:
      self.pos[0] -= dx*sens
      self.pos[2] += dz*sens
      if keys[key.A]:
      self.pos[0] -= dz*sens
      self.pos[2] -= dx*sens
      if keys[key.D]:
      self.pos[0] += dz*sens
      self.pos[2] += dx*sens
      if keys[key.SPACE]:
      self.pos[1] += s
      if keys[key.LSHIFT]:
      self.pos[1] -= s

      class Window(pyglet.window.Window):

      def push(self,pos,rot):
      glPushMatrix()
      rot = self.player.rot
      pos = self.player.pos
      glRotatef(-rot[0],1,0,0)
      glRotatef(-rot[1],0,1,0)
      glTranslatef(-pos[0], -pos[1], -pos[2])

      def Projection(self):
      glMatrixMode(GL_PROJECTION)
      glLoadIdentity()

      def Model(self):
      glMatrixMode(GL_MODELVIEW)
      glLoadIdentity()

      def set2d(self):
      self.Projection()
      gluPerspective(0, self.width, 0, self.height)
      self.Model()

      def set3d(self):
      self.Projection()
      gluPerspective(70, self.width/self.height, 0.05, 1000)
      self.Model()

      def setLock(self, state):
      self.lock = state
      self.set_exclusive_mouse(state)

      lock = False
      mouse_lock = property(lambda self:self.lock, setLock)

      def __init__(self, *args, **kwargs):
      super().__init__(*args, **kwargs)
      self.set_minimum_size(300,200)
      self.keys = key.KeyStateHandler()
      self.push_handlers(self.keys)
      pyglet.clock.schedule(self.update)

      self.model = Model()
      self.player = Player((0.5,1.5,1.5),(-30,0))

      def on_mouse_motion(self,x,y,dx,dy):
      if self.mouse_lock: self.player.mouse_motion(dx,dy)

      def on_key_press(self, KEY, _MOD):
      if KEY == key.ESCAPE:
      self.close()
      elif KEY == key.E:
      self.mouse_lock = not self.mouse_lock

      def update(self, dt):
      self.player.update(dt, self.keys)

      def on_draw(self):
      self.clear()
      self.set3d()
      self.push(self.player.pos,self.player.rot)
      self.model.draw()
      glPopMatrix()

      if __name__ == '__main__':
      window = Window(width=400, height=300, caption='Terrain Viewer', resizable=True)
      glClearColor(0, 0, 0, 1)
      glEnable(GL_DEPTH_TEST)
      pyglet.app.run()






      python python-3.x opengl pyglet






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 '18 at 22:35









      genpfault

      41.8k95298




      41.8k95298










      asked Nov 12 '18 at 22:24









      Danger ZoneDanger Zone

      508




      508
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270972%2fstop-gl-triangle-strip-from-connecting-last-and-first-vertex%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270972%2fstop-gl-triangle-strip-from-connecting-last-and-first-vertex%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Florida Star v. B. J. F.

          Danny Elfman

          Lugert, Oklahoma