2012-06-20 17 views
6

मेरे पास पृष्ठभूमि छवि है I open gl 1.0 es के साथ चित्रित कर रहा हूं।एक दूसरे के बगल में जीएल 10 ड्राइंग छवियों से लाइनें प्राप्त करना, समाधान?

समस्या है जब मैं बड़े परदे मैं इस पाने के लिए इस छोटे छवि आकर्षित ...

enter image description here

लाइनों/पैटर्न में टूट जाता है वहाँ होने के लिए लगता है कि नहीं कर रहे हैं। मैंने बहुत सी चीजों की कोशिश की है, मैंने सोचा कि शायद मेरा एटलस गलत था ... संदेह है। मैं इसे (0, 0, 50, 50) से खींचता हूं जो (x, y, चौड़ाई, ऊंचाई) है। इसे बहुत जांच लिया और फिर भी वही परिणाम मिलता है, जैसा कि यह होना चाहिए।

पाश जो नीचे है के लिए मेरे साथ अलग अलग बातें की कोशिश की ...

GL10 gl = this.glGraphics.getGL(); 
     gl.glClear(GL10.GL_COLOR_BUFFER_BIT); 
     guiCam.setViewportAndMatrices(); 

     gl.glEnable(GL10.GL_TEXTURE_2D); 

     // Set background color // 

     batcher.beginBatch(Assets.mainmenuAtlas); 

     for(int x = Assets.mmbackgroundPattern.width/2; x < this.scale.getWidth() + Assets.mmbackgroundPattern.width/2; x += Assets.mmbackgroundPattern.width) { 
      for(int y = Assets.mmbackgroundPattern.height/2; y < this.scale.getHeight() + Assets.mmbackgroundPattern.height/2; y += Assets.mmbackgroundPattern.height) { 
       batcher.drawSprite(x, y, Assets.mmbackgroundPattern.width, Assets.mmbackgroundPattern.height, Assets.mmbackgroundPattern); 
      } 
     } 

व्यूपोर्ट & मैट्रिक्स है:

public void setViewportAndMatrices() { 
     GL10 gl = glGraphics.getGL(); 
     gl.glViewport(0, 0, glGraphics.getWidth(), glGraphics.getHeight()); 
     gl.glMatrixMode(GL10.GL_PROJECTION); 
     gl.glLoadIdentity(); 
     gl.glOrthof(position.x - frustumWidth * zoom/2, 
        position.x + frustumWidth * zoom/ 2, 
        position.y - frustumHeight * zoom/2, 
        position.y + frustumHeight * zoom/ 2, 
        1, -1); 
     gl.glMatrixMode(GL10.GL_MODELVIEW); 
     gl.glLoadIdentity(); 
    } 

जब मैं स्प्राइट आकर्षित:

public void endBatch() { 
     vertices.setVertices(verticesBuffer, 0, bufferIndex); 
     vertices.bind(); 
     vertices.draw(GL10.GL_TRIANGLES, 0, numSprites * 6); 
     vertices.unbind(); 
    } 

    public void drawSprite(float x, float y, float width, float height, TextureRegion region) { 
     float halfWidth = width/2; 
     float halfHeight = height/2; 
     float x1 = x - halfWidth; 
     float y1 = y - halfHeight; 
     float x2 = x + halfWidth; 
     float y2 = y + halfHeight; 

     verticesBuffer[bufferIndex++] = x1; 
     verticesBuffer[bufferIndex++] = y1; 
     verticesBuffer[bufferIndex++] = region.u1; 
     verticesBuffer[bufferIndex++] = region.v2; 

     verticesBuffer[bufferIndex++] = x2; 
     verticesBuffer[bufferIndex++] = y1; 
     verticesBuffer[bufferIndex++] = region.u2; 
     verticesBuffer[bufferIndex++] = region.v2; 

     verticesBuffer[bufferIndex++] = x2; 
     verticesBuffer[bufferIndex++] = y2; 
     verticesBuffer[bufferIndex++] = region.u2; 
     verticesBuffer[bufferIndex++] = region.v1; 

     verticesBuffer[bufferIndex++] = x1; 
     verticesBuffer[bufferIndex++] = y2; 
     verticesBuffer[bufferIndex++] = region.u1; 
     verticesBuffer[bufferIndex++] = region.v1; 

     numSprites++; 
    } 

यहाँ मेरे बनावट और बनावट क्षेत्र हैं:

public TextureRegion(Texture texture, float x, float y, float width, float height) { 
     this.u1 = x/texture.width; 
     this.v1 = y/texture.height; 
     this.u2 = this.u1 + width/texture.width; 
     this.v2 = this.v1 + height/texture.height;   
     this.texture = texture; 

     this.width = (int) width; 
     this.height = (int) height; 
    } 

public class Texture { 
    GLGraphics glGraphics; 
    FileIO fileIO; 
    Bitmap img; 
    String fileName; 
    int textureId; 
    int minFilter; 
    int magFilter; 
    public int width; 
    public int height; 

    public Texture(GLGame glGame, String fileName) { 
     this.glGraphics = glGame.getGLGraphics(); 
     this.fileIO = glGame.getFileIO(); 
     this.fileName = fileName; 
     try { 
      load(BitmapFactory.decodeStream(this.fileIO.readAsset(fileName))); 
     } catch(Exception e) { 
      e.printStackTrace(); 
     } 
    } 

    public Texture(GLGame glGame, Bitmap img) { 
     this.glGraphics = glGame.getGLGraphics(); 
     this.fileIO = glGame.getFileIO(); 
     this.img = img; 
     load(img); 
    } 

    private void load(Bitmap bitmap) { 
     GL10 gl = glGraphics.getGL(); 
     int[] textureIds = new int[1]; 
     gl.glGenTextures(1, textureIds, 0); 
     textureId = textureIds[0]; 

     gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId); 
     GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0); 
     setFilters(GL10.GL_LINEAR, GL10.GL_LINEAR); 
     gl.glBindTexture(GL10.GL_TEXTURE_2D, 0); 
     width = bitmap.getWidth(); 
     height = bitmap.getHeight(); 
     bitmap.recycle(); 
    } 

    public void reload() { 
     if(fileName.equals(null)) { 
      load(this.img); 
     } else { 
      try { 
       load(BitmapFactory.decodeStream(this.fileIO.readAsset(fileName))); 
      } catch(Exception e) { 
       e.printStackTrace(); 
      } 
     } 
     bind(); 
     setFilters(minFilter, magFilter);   
     glGraphics.getGL().glBindTexture(GL10.GL_TEXTURE_2D, 0); 
    } 

    public void setFilters(int minFilter, int magFilter) { 
     this.minFilter = minFilter; 
     this.magFilter = magFilter; 
     GL10 gl = glGraphics.getGL(); 
     gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, minFilter); 
     gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, magFilter); 
    }  

    public void bind() { 
     GL10 gl = glGraphics.getGL(); 
     gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId); 
    } 

    public void dispose() { 
     GL10 gl = glGraphics.getGL(); 
     gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId); 
     int[] textureIds = { textureId }; 
     gl.glDeleteTextures(1, textureIds, 0); 
    } 
} 

मैंने चौड़ाई और ऊंचाई जोड़ने से जोड़ने और घटाने का प्रयास किया है, लेकिन यह बदतर दिखता है।

मेरा प्रश्न क्या आप कोशिश करते हैं और इस समस्या को ठीक करने के लिए को देखो होता है, मैं बहुत स्टंप्डया लग रहा है, लेकिन मुझे लगता है कि मैं कुछ OpenGL में गलत सेट कर सकता है। मैं गलत क्या सेटअप कर सकता था? मैं हमेशा अधिक कोड ऊपर प्रदान कर सकता हूं, लेकिन यह सुनिश्चित नहीं करता कि आपको क्या चाहिए।

छवि मैं पूरी स्क्रीन पर चिपकाने फिर से कर रहा हूँ है:

enter image description here

इसके अलावा उपकरण मैं एटलस बनाने के लिए उपयोग कर रहा हूँ found here है और मैं बीटा पेड़ जो निर्माण में माना जाता है के तहत एक का उपयोग कर रहा 4. हालांकि, मैंने एटलस की जांच की और यह ठीक लगता है।

public class SpriteBatcher {   
    final float[] verticesBuffer; 
    int bufferIndex; 
    final Vertices vertices; 
    int numSprites;  

    public SpriteBatcher(GLGraphics glGraphics, int maxSprites) {     
     this.verticesBuffer = new float[maxSprites*4*4];   
     this.vertices = new Vertices(glGraphics, maxSprites*4, maxSprites*6, false, true); 
     this.bufferIndex = 0; 
     this.numSprites = 0; 

     short[] indices = new short[maxSprites*6]; 
     int len = indices.length; 
     short j = 0; 
     for (int i = 0; i < len; i += 6, j += 4) { 
       indices[i + 0] = (short)(j + 0); 
       indices[i + 1] = (short)(j + 1); 
       indices[i + 2] = (short)(j + 2); 
       indices[i + 3] = (short)(j + 2); 
       indices[i + 4] = (short)(j + 3); 
       indices[i + 5] = (short)(j + 0); 
     } 
     vertices.setIndices(indices, 0, indices.length);     
    } 

     public void drawSprite(float x, float y, float width, float height, TextureRegion region, boolean corner) { 
       if(corner) { 
        float x1 = x; 
        float y1 = y; 
        float x2 = x + width; 
        float y2 = y + height; 

        verticesBuffer[bufferIndex++] = x1; 
        verticesBuffer[bufferIndex++] = y1; 
        verticesBuffer[bufferIndex++] = region.u1; 
        verticesBuffer[bufferIndex++] = region.v2; 

        verticesBuffer[bufferIndex++] = x2; 
        verticesBuffer[bufferIndex++] = y1; 
        verticesBuffer[bufferIndex++] = region.u2; 
        verticesBuffer[bufferIndex++] = region.v2; 

        verticesBuffer[bufferIndex++] = x2; 
        verticesBuffer[bufferIndex++] = y2; 
        verticesBuffer[bufferIndex++] = region.u2; 
        verticesBuffer[bufferIndex++] = region.v1; 

        verticesBuffer[bufferIndex++] = x1; 
        verticesBuffer[bufferIndex++] = y2; 
        verticesBuffer[bufferIndex++] = region.u1; 
        verticesBuffer[bufferIndex++] = region.v1; 

        numSprites++; 
       } else { 
        drawSprite(x, y, width, height, region); 
       } 
      } 

    public void present(float deltaTime) { 
      GL10 gl = this.glGraphics.getGL(); 
      gl.glClear(GL10.GL_COLOR_BUFFER_BIT); 
      guiCam.setViewportAndMatrices(); 

      gl.glEnable(GL10.GL_TEXTURE_2D); 

      // Set background color // 

      batcher.beginBatch(Assets.mainmenuAtlas); 

      for(float x = 0; x < this.scale.getWidth(); x += Assets.mmbackgroundPattern.width) { 
       for(float y = 0; y < this.scale.getHeight(); y += Assets.mmbackgroundPattern.height) { 
        batcher.drawSprite(x, y, Assets.mmbackgroundPattern.width, Assets.mmbackgroundPattern.height, Assets.mmbackgroundPattern, true); 


    } 
     } 
+0

कोड मुझे 'libgdx' की याद दिलाता है। सीमा पर एक पिक्सेल का ओवरलैप है; मुझे यकीन है कि मिश्रण एक मुद्दा हो सकता है। –

+0

@StefanHanke ठीक है, तो एक ओवरलैप है, आप इसे ठीक करने के बारे में कैसे जाएंगे? मैंने एटलस से एक कम पिक्सेल काटने की कोशिश की ... काम नहीं करता है। वास्तव में, यह बदतर बना देता है। क्या मैं कुछ अलग कर सकता हूं? इसके अलावा मैंने मिश्रण करने की कोशिश की, लेकिन मदद नहीं की और न ही बाधा उत्पन्न हुई। – Zeveso

+2

कोड फ्लोट का उपयोग करता है, जो आस-पास विभाजित करता है, लेकिन आखिरकार इसे पूर्णांक स्क्रीन निर्देशांक में मैप किया जाएगा। एक 'drawSprite' int int पैरामीटर बनाएं जो विभाजित नहीं करता है। –

उत्तर

3

क्या आप GL_LINEAR के बजाय GL_NEAREST फ़िल्टरिंग का उपयोग करने का प्रयास कर सकते हैं? आपको अपने किनारे पिक्सल और सीमा रंग के बीच कुछ रैखिक नमूना मिल रहा है।

विशेष रूप से यहाँ:

setFilters(GL10.GL_LINEAR, GL10.GL_LINEAR); 
+0

आप सही थे, आपको बहुत धन्यवाद!यह दूसरी बार है जब आपने मुझे एक ही चीज़ से बचाया! सच में! मैं इसके बारे में और कहां से जान सकता हूं ... मैं सिर्फ ओपन-ग्ल/ओपनग्ल-एस शुरू कर रहा हूं, तो क्या कोई ऐसी पुस्तक है जिसे आप सुझाव देंगे या दूसरा माध्यम? – Zeveso

संबंधित मुद्दे