ofShortPixels doesn't draw pixels correctly


I have question about ofShortPixels and ofShortColor.

If you execute the code below , it’ll draw at half way screen height even though I did set aDot at (0. screen height / 4)

And another weird thing is it draws 20 pixels instead of 10 pixels which I set for loop for 10 times.

It only draws correctly with ofPixels and ofColor.

It doesn’t work with ofFloatPixels and ofFloatColor.

Please help me out.

I need to have RGB value over 255 so I can check if those values are over 255.

Thanks in advanced


.h file

#pragma once  
#include "ofMain.h"  
class Dot  {      
    ofVec2f location;  
class testApp : public ofBaseApp{      
    void setup();  
    void update();  
    void draw();  
    int w,h;  
    ofTexture particleTexture;  
    ofShortPixels * rgbPixels;  
    ofShortColor&  paint(ofShortColor &);  
    Dot aDot;  

.cpp file

#include "testApp.h"  
void testApp::setup(){  
    ofBackground(0, 0, 0);  
    w = ofGetWidth();  
    h = ofGetHeight();  
    rgbPixels = new ofShortPixels;  
    rgbPixels->allocate(w, h, 3);  
    aDot.location.set(0, h/4);  
void testApp::update(){  
    ofShortColor pixelColor;  
    ofShortColor newPixelColor;  
    for(int i = 0; i<10; i++){  
        pixelColor = rgbPixels->getColor(aDot.location.x+i, aDot.location.y);  
        newPixelColor = paint(pixelColor);  
        rgbPixels->setColor(aDot.location.x+i, aDot.location.y,newPixelColor);  
    particleTexture.loadData(* rgbPixels);  
void testApp::draw(){  
    particleTexture.draw(0, 0, w, h);  
ofShortColor &  testApp::paint(ofShortColor & _c){  
    _c.r += 10;  
    _c.g += 2;  
    _c.b += 3;  
    _c.set(_c.r, _c.g, _c.b);  
    return _c;  

sorry to hijack you thread.
but what does ofShortPixels do? it’s the first time i hear about this.

1 Like

Well, I’ve spent all morning hacking around on this and I’m stumped. No combination of setting the texture data, pixelType, GL_RGB16, GL_UNSIGNED_SHORT, or method of uploading the texture seems to get this right. I’d say file it as a bug on github for the time being if you could. I’ve got to go do some actual work, but I’ll see if I can come back to it this evening.

@joshua noble
I see…
I don’t know how to use jithub… have never been there…
Maybe…can I just upload on the board of “bugs…errors”?

I can answer as far as I know though.
ofPixels only deal with char data which is up to 255.
However, if you need to deal with numbers bigger than 255, you can use ofShortPixels which is short integer.
I was not really using numbers over 255 to color pixels but just for doing some other calculation.
In my case(additive color blending), I needed to check numbers over 255 but ofPixels doesn’t go over 255.