| @@ -10,5 +10,5 @@ | |||||
| examples/app | examples/app | ||||
| examples/color | examples/color | ||||
| examples/image | |||||
| examples/images | |||||
| examples/nekobi-ui | examples/nekobi-ui | ||||
| @@ -45,9 +45,9 @@ public: | |||||
| GLenum getFormat() const noexcept; | GLenum getFormat() const noexcept; | ||||
| GLenum getType() const noexcept; | GLenum getType() const noexcept; | ||||
| void draw() const; | |||||
| void draw(int x, int y) const; | |||||
| void draw(const Point<int>& pos) const; | |||||
| void draw(); | |||||
| void draw(int x, int y); | |||||
| void draw(const Point<int>& pos); | |||||
| Image& operator=(const Image& image) noexcept; | Image& operator=(const Image& image) noexcept; | ||||
| bool operator==(const Image& image) const noexcept; | bool operator==(const Image& image) const noexcept; | ||||
| @@ -58,7 +58,7 @@ private: | |||||
| Size<int> fSize; | Size<int> fSize; | ||||
| GLenum fFormat; | GLenum fFormat; | ||||
| GLenum fType; | GLenum fType; | ||||
| mutable GLuint fTextureId; | |||||
| GLuint fTextureId; | |||||
| }; | }; | ||||
| // ----------------------------------------------------------------------- | // ----------------------------------------------------------------------- | ||||
| @@ -16,8 +16,6 @@ | |||||
| #include "../Image.hpp" | #include "../Image.hpp" | ||||
| #include <cstdio> | |||||
| START_NAMESPACE_DGL | START_NAMESPACE_DGL | ||||
| // ----------------------------------------------------------------------- | // ----------------------------------------------------------------------- | ||||
| @@ -115,12 +113,12 @@ GLenum Image::getType() const noexcept | |||||
| return fType; | return fType; | ||||
| } | } | ||||
| void Image::draw() const | |||||
| void Image::draw() | |||||
| { | { | ||||
| draw(0, 0); | draw(0, 0); | ||||
| } | } | ||||
| void Image::draw(int x, int y) const | |||||
| void Image::draw(int x, int y) | |||||
| { | { | ||||
| if (! isValid()) | if (! isValid()) | ||||
| return; | return; | ||||
| @@ -128,7 +126,8 @@ void Image::draw(int x, int y) const | |||||
| glGenTextures(1, &fTextureId); | glGenTextures(1, &fTextureId); | ||||
| if (fTextureId == 0) | if (fTextureId == 0) | ||||
| { | { | ||||
| printf("texture Id still 0\n"); | |||||
| // invalidate image | |||||
| fSize = Size<int>(0, 0); | |||||
| return; | return; | ||||
| } | } | ||||
| @@ -147,39 +146,28 @@ void Image::draw(int x, int y) const | |||||
| float trans[] = { 0.0f, 0.0f, 0.0f, 0.0f }; | float trans[] = { 0.0f, 0.0f, 0.0f, 0.0f }; | ||||
| glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, trans); | glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, trans); | ||||
| glPushMatrix(); | |||||
| const GLint w2 = getWidth()/2; | |||||
| const GLint h2 = getHeight()/2; | |||||
| glTranslatef(x+w2, y+h2, 0.0f); | |||||
| const int width = getWidth(); | |||||
| const int height = getHeight(); | |||||
| glBegin(GL_QUADS); | glBegin(GL_QUADS); | ||||
| glTexCoord2f(0.0f, 1.0f); | |||||
| glVertex2i(-w2, -h2); | |||||
| glTexCoord2f(1.0f, 1.0f); | |||||
| glVertex2i(getWidth()-w2, -h2); | |||||
| glTexCoord2f(0.0f, 0.0f); | |||||
| glVertex2i(x, y); | |||||
| glTexCoord2f(1.0f, 0.0f); | glTexCoord2f(1.0f, 0.0f); | ||||
| glVertex2i(getWidth()-w2, getHeight()-h2); | |||||
| glVertex2i(x+width, y); | |||||
| glTexCoord2f(0.0f, 0.0f); | |||||
| glVertex2i(-w2, getHeight()-h2); | |||||
| glEnd(); | |||||
| glTexCoord2f(1.0f, 1.0f); | |||||
| glVertex2i(x+width, y+height); | |||||
| glPopMatrix(); | |||||
| glTexCoord2f(0.0f, 1.0f); | |||||
| glVertex2i(x, y+height); | |||||
| glEnd(); | |||||
| glBindTexture(GL_TEXTURE_2D, 0); | glBindTexture(GL_TEXTURE_2D, 0); | ||||
| glDisable(GL_TEXTURE_2D); | glDisable(GL_TEXTURE_2D); | ||||
| // glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | |||||
| // glPixelStorei(GL_PACK_ALIGNMENT, 1); | |||||
| // glRasterPos2i(x, fSize.getHeight()+y); | |||||
| // glDrawPixels(fSize.getWidth(), fSize.getHeight(), fFormat, fType, fRawData); | |||||
| } | } | ||||
| void Image::draw(const Point<int>& pos) const | |||||
| void Image::draw(const Point<int>& pos) | |||||
| { | { | ||||
| draw(pos.getX(), pos.getY()); | draw(pos.getX(), pos.getY()); | ||||
| } | } | ||||
| @@ -38,7 +38,7 @@ app: app.cpp ../dgl/* | |||||
| color: color.cpp ../dgl/* | color: color.cpp ../dgl/* | ||||
| $(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ | $(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ | ||||
| images: images.cpp ../dgl/* | |||||
| images: images.cpp images_src/* ../dgl/* | |||||
| $(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ | $(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ | ||||
| nekobi-ui: nekobi-ui.cpp nekobi-ui_src/* ../dgl/* | nekobi-ui: nekobi-ui.cpp nekobi-ui_src/* ../dgl/* | ||||
| @@ -108,16 +108,16 @@ private: | |||||
| glColor3b(r, g, b); | glColor3b(r, g, b); | ||||
| glBegin(GL_QUADS); | glBegin(GL_QUADS); | ||||
| glTexCoord2i(x, y); | |||||
| glTexCoord2f(0.0f, 0.0f); | |||||
| glVertex2i(x, y); | glVertex2i(x, y); | ||||
| glTexCoord2i(x+width, y); | |||||
| glTexCoord2f(1.0f, 0.0f); | |||||
| glVertex2i(x+width, y); | glVertex2i(x+width, y); | ||||
| glTexCoord2i(x+width, y+height); | |||||
| glTexCoord2f(1.0f, 1.0f); | |||||
| glVertex2i(x+width, y+height); | glVertex2i(x+width, y+height); | ||||
| glTexCoord2i(x, y+height); | |||||
| glTexCoord2f(0.0f, 1.0f); | |||||
| glVertex2i(x, y+height); | glVertex2i(x, y+height); | ||||
| glEnd(); | glEnd(); | ||||
| @@ -131,16 +131,16 @@ private: | |||||
| glColor3b(100-r, 100-g, 100-b); | glColor3b(100-r, 100-g, 100-b); | ||||
| glBegin(GL_QUADS); | glBegin(GL_QUADS); | ||||
| glTexCoord2i(x, y); | |||||
| glTexCoord2f(0.0f, 0.0f); | |||||
| glVertex2i(x, y); | glVertex2i(x, y); | ||||
| glTexCoord2i(x+width, y); | |||||
| glTexCoord2f(1.0f, 0.0f); | |||||
| glVertex2i(x+width, y); | glVertex2i(x+width, y); | ||||
| glTexCoord2i(x+width, y+height); | |||||
| glTexCoord2f(1.0f, 1.0f); | |||||
| glVertex2i(x+width, y+height); | glVertex2i(x+width, y+height); | ||||
| glTexCoord2i(x, y+height); | |||||
| glTexCoord2f(0.0f, 1.0f); | |||||
| glVertex2i(x, y+height); | glVertex2i(x, y+height); | ||||
| glEnd(); | glEnd(); | ||||
| } | } | ||||
| @@ -31,7 +31,7 @@ def png2rgba(namespace, filenames): | |||||
| png = Image.open(filename) | png = Image.open(filename) | ||||
| pngNumpy = numpy.array(png) | pngNumpy = numpy.array(png) | ||||
| pngData = pngNumpy.tolist() | pngData = pngNumpy.tolist() | ||||
| pngData.reverse() | |||||
| #pngData.reverse() | |||||
| height = len(pngData) | height = len(pngData) | ||||
| for dataBlock in pngData: | for dataBlock in pngData: | ||||