Loading...
Logo
Processing Forum
I am working on a sketch using the OpenGL render mode and I am getting an error "Adding same texture twice" and I'm trying to figure out what that means. 

I looked it up in the source code and it is generated by a function called  createTextureObject. Anyone know what the significance of this message is?
Copy code
  1. // Texture Objects -----------------------------------------------------------

    protected int createTextureObject(int context) {
    deleteFinalizedTextureObjects();

    int[] temp = new int[1];
    pgl.genTextures(1, temp, 0);
    int id = temp[0];

    GLResource res = new GLResource(id, context);

    if (glTextureObjects.containsKey(res)) {
    showWarning("Adding same texture twice");
    } else {
    glTextureObjects.put(res, false);
    }

    return id;
    }


Here's the code I'm running that's generating the warning:
Copy code
  1. import processing.opengl.*;

  2. //Declare Globals
  3. float PHI = 0.618033989;

  4. int rotationMode = 0;
  5. // 0 = rotate in 90deg increments
  6. // 1 = fine increments (cn.val * TWO_PI)

  7. int xRes, yRes;
  8. float cellH, cellW;

  9. PImage src;
  10. float imgTileW;
  11. float imgTileH;

  12. Node[] nodeField;

  13. void setup() {
  14.   background(255);
  15.   size(1200, 800, OPENGL);
  16.   smooth();
  17.   colorMode(RGB, 255, 255, 255, 255);
  18.   xRes = 30;
  19.   yRes = 20;

  20.   cellH = height/yRes;
  21.   cellW = width/xRes;

  22.   src = loadImage("andrew.jpeg");
  23.   imgTileW = src.width/xRes;
  24.   imgTileH = src.height/yRes;

  25.   nodeField = new Node[xRes * yRes];

  26.   for (int i=0; i < nodeField.length; i++) {
  27.     Node n = new Node();

  28.     n.gridLoc.x = i % xRes;
  29.     n.gridLoc.y = floor(i / xRes);

  30.     n.loc.x = n.gridLoc.x * cellW;
  31.     n.loc.y = n.gridLoc.y * cellH;
  32.     
  33.     nodeField[i] = n;
  34.   }
  35. }

  36. void draw() {
  37.    background(255);

  38.   for (Node n : nodeField) {
  39.     n.val = noise((n.gridLoc.x  + frameCount/10) * 0.05, (n.gridLoc.y) * .05);
  40.   }
  41.   for (int i=0; i < nodeField.length; i++) {
  42.     Node cn = nodeField[i];
  43.     fill(0);
  44.     noStroke();
  45.     smooth();

  46.     pushMatrix();
  47.     translate(cn.loc.x + (cellW/2), cn.loc.y + (cellH/2));
  48.     if (rotationMode == 0) {
  49.       if (cn.val < 0.25) {
  50.         rotate(0);
  51.       }
  52.       else if (cn.val > 0.25 && cn.val < 0.5) {
  53.         rotate(PI/2);
  54.       }
  55.       else if (cn.val > 0.5 && cn.val < 0.75) {
  56.         rotate(PI);
  57.       }
  58.       else if (cn.val > 0.75) {
  59.         rotate(PI/2+PI);
  60.       }
  61.     }
  62.     else if (rotationMode == 1) {
  63.       rotate(cn.val * TWO_PI);
  64.       }

  65.       PImage tile = src.get(int(cn.gridLoc.x * imgTileW), int(cn.gridLoc.y * imgTileH), int(imgTileW), int(imgTileH));
  66.     image(tile, -cellW/2, -cellH/2, cellW, cellH); 
  67.     popMatrix();
  68.   }
  69.  }


  70. class Node {
  71.   PVector loc = new PVector();
  72.   float val;
  73.   PVector gridLoc = new PVector();
  74. }

Replies(1)

line 82 is in a for loop thus you load tile twice.

do it before the loop?