From 95c6c168514a8a9d769a1ca39cc8cedb5fa4969d Mon Sep 17 00:00:00 2001 From: ehofman Date: Sat, 12 Apr 2003 09:29:18 +0000 Subject: [PATCH] Move the texture object to the screen directory for the sake of library dependencies --- simgear/misc/Makefile.am | 2 -- simgear/screen/Makefile.am | 7 ++++++- simgear/{misc => screen}/texture.cxx | 29 +++++++++++++++++++++++++--- simgear/{misc => screen}/texture.hxx | 10 ++++++++++ 4 files changed, 42 insertions(+), 6 deletions(-) rename simgear/{misc => screen}/texture.cxx (95%) rename simgear/{misc => screen}/texture.hxx (86%) diff --git a/simgear/misc/Makefile.am b/simgear/misc/Makefile.am index d961b03c..a3616de3 100644 --- a/simgear/misc/Makefile.am +++ b/simgear/misc/Makefile.am @@ -15,7 +15,6 @@ include_HEADERS = \ stopwatch.hxx \ strutils.hxx \ tabbed_values.hxx \ - texture.hxx \ texcoord.hxx \ zfstream.hxx @@ -28,7 +27,6 @@ libsgmisc_a_SOURCES = \ sgstream.cxx \ strutils.cxx \ tabbed_values.cxx \ - texture.cxx \ texcoord.cxx \ zfstream.cxx diff --git a/simgear/screen/Makefile.am b/simgear/screen/Makefile.am index aa16a1d8..5e8fe44b 100644 --- a/simgear/screen/Makefile.am +++ b/simgear/screen/Makefile.am @@ -12,9 +12,14 @@ IMAGE_SERVER_INCL = IMAGE_SERVER_SRCS = endif -include_HEADERS = $(IMAGE_SERVER_INCL) screen-dump.hxx tr.h +include_HEADERS = \ + texture.hxx \ + $(IMAGE_SERVER_INCL) \ + screen-dump.hxx \ + tr.h libsgscreen_a_SOURCES = \ + texture.cxx \ GLBitmaps.cxx GLBitmaps.h \ $(IMAGE_SERVER_SRCS) \ screen-dump.cxx \ diff --git a/simgear/misc/texture.cxx b/simgear/screen/texture.cxx similarity index 95% rename from simgear/misc/texture.cxx rename to simgear/screen/texture.cxx index b90f8635..764ede05 100644 --- a/simgear/misc/texture.cxx +++ b/simgear/screen/texture.cxx @@ -25,7 +25,7 @@ SGTexture::SGTexture() SGTexture::SGTexture(unsigned int width, unsigned int height) { - texture_data = new GLubyte[ width*height*3 ]; + texture_data = new GLubyte[ width * height * 3 ]; } SGTexture::~SGTexture() @@ -275,8 +275,8 @@ SGTexture::read_raw_texture(const char *name) ptr = texture_data; for(y=0; y<256; y++) { - gzread(image->file, ptr, 256*3); - ptr+=256*3; + gzread(image->file, ptr, 256*3); + ptr+=256*3; } ImageClose(image); } @@ -320,6 +320,28 @@ SGTexture::read_r8_texture(const char *name) } +void +SGTexture::set_pixel(GLuint x, GLuint y, sgVec3 &c) +{ + unsigned int pos = (x + y*texture_width)*3; + texture_data[pos] = c[0]; + texture_data[pos+1] = c[1]; + texture_data[pos+2] = c[2]; +} + + +sgVec3 * +SGTexture::get_pixel(GLuint x, GLuint y) +{ + static sgVec3 c; + unsigned int pos = (x + y*texture_width)*3; + + sgSetVec3(c, texture_data[pos], texture_data[pos+1], texture_data[pos+2]); + + return &c; +} + + SGTexture::ImageRec * SGTexture::ImageOpen(const char *fileName) { @@ -493,6 +515,7 @@ SGTexture::ConvertShort(unsigned short *array, unsigned int length) { } } + void SGTexture::ConvertUint(unsigned *array, unsigned int length) { unsigned int b1, b2, b3, b4; diff --git a/simgear/misc/texture.hxx b/simgear/screen/texture.hxx similarity index 86% rename from simgear/misc/texture.hxx rename to simgear/screen/texture.hxx index 908367c9..2a1b5c5c 100644 --- a/simgear/misc/texture.hxx +++ b/simgear/screen/texture.hxx @@ -5,6 +5,8 @@ #include #include +#include + class SGTexture { private: @@ -64,9 +66,17 @@ public: inline int width() { return texture_width; } inline int height() { return texture_height; } + // dynamic texture functions. + // everything drawn to the OpenGL screen after prepare is + // called and before finish is called will be included + // in the new texture. void prepare(unsigned int width = 256, unsigned int height = 256); void finish(unsigned int width, unsigned int height); + // texture pixel manipulation functions. + void set_pixel(GLuint x, GLuint y, sgVec3 &c); + sgVec3 *get_pixel(GLuint x, GLuint y); + void bind(); inline void select() { // if (texture_data) -- 2.39.5