Permalink
Browse files

Split texture and image into 2 differen objects.

  • Loading branch information...
batiste committed Jun 26, 2012
1 parent 512c862 commit cc03603d158928f12eb5a387f793a93c5b81239f
Showing with 39 additions and 27 deletions.
  1. BIN assets/bamboo-2.png
  2. BIN assets/bamboo-b2.png
  3. +9 −7 common.c
  4. +30 −20 my_app.c
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -365,6 +365,7 @@ struct ImageData {
char * filename;
GLuint type;
};
+typedef struct ImageData ImageData;
struct TextureInfos {
float x;
@@ -387,6 +388,7 @@ struct TextureInfos {
GLuint indexBuffer;
GLushort * indices;
};
+typedef struct TextureInfos TextureInfos;
@greut

greut Jun 26, 2012

Contributor

you can do that in the same declaration.

typedef struct ImageData {
    …
} ImageData;
void convertBGRAtoRGBA(char * bgra, int num)
@@ -415,7 +417,7 @@ void convertBGRtoRGB(char * bgr, int num)
}
}
-void loadPNG(struct ImageData * data)
+void loadPNG(ImageData * data)
{
unsigned error;
int size;
@@ -433,7 +435,7 @@ void loadPNG(struct ImageData * data)
data->type = GL_RGBA;
}
-void loadBMP(struct ImageData * data)
+void loadBMP(ImageData * data)
{
// This surface will tell us the details of the image
SDL_Surface * surface;
@@ -508,7 +510,7 @@ void loadBMP(struct ImageData * data)
}
-int checkImageDimension(struct ImageData * data) {
+int checkImageDimension(ImageData * data) {
int max_size;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_size);
LOG("Max image size %d", max_size);
@@ -529,7 +531,7 @@ int checkImageDimension(struct ImageData * data) {
}
int
-loadTexture(struct TextureInfos * infos, struct ImageData * data, float xscale, float yscale) {
+loadTexture(TextureInfos * infos, ImageData * data, float xscale, float yscale) {
CHECK_GL();
// glPixelStorei(GL_PACK_ALIGNMENT, 4);
@@ -635,7 +637,7 @@ loadTexture(struct TextureInfos * infos, struct ImageData * data, float xscale,
}
-int drawTexture(struct TextureInfos * texture, float x, float y, float angle) {
+int drawTexture(TextureInfos * texture, float x, float y, float angle) {
// Specifies the byte offset between consecutive generic vertex attributes.
// If stride is 0, the generic vertex attributes are understood to be tightly packed in the array
@@ -675,7 +677,7 @@ int drawTexture(struct TextureInfos * texture, float x, float y, float angle) {
CHECK_GL();
}
-int drawBufferTexture(struct TextureInfos * texture, float x, float y, float angle) {
+int drawBufferTexture(TextureInfos * texture, float x, float y, float angle) {
// Specifies the byte offset between consecutive generic vertex attributes.
// If stride is 0, the generic vertex attributes are understood to be tightly packed in the array
@@ -719,7 +721,7 @@ int drawBufferTexture(struct TextureInfos * texture, float x, float y, float ang
//CHECK_GL();
}
-GLfloat * transformTexture(struct TextureInfos * texture, float tx, float ty, float angle) {
+GLfloat * transformTexture(TextureInfos * texture, float tx, float ty, float angle) {
// transform all the vertices of the current textureInfos object
int i, j;
View
@@ -20,21 +20,21 @@ int main(int argc, char** argv)
CHECK_GL();
// load texture
- struct ImageData png;
+ ImageData png;
png.filename = "bamboo-2.png";
@greut

greut Jun 26, 2012

Contributor
ImageData png = { .filename = "bamboo-2.png" };
loadPNG(&png);
- struct TextureInfos texture;
+ TextureInfos texture;
loadTexture(&texture, &png, 1.0, 1.0);
transformTexture(&texture, 0.0, 0.0, 0.0);
// load texture
- struct ImageData background;
+ ImageData background;
background.filename = "bamboo-b2.png";
loadPNG(&background);
- struct TextureInfos back;
+ TextureInfos back;
float scalex = screen.w / (float)background.width;
loadTexture(&back, &background, scalex, scalex);
transformTexture(&back, 0, -back.height / 2.0 + screen.h / 2.0, 0);
@@ -65,7 +65,7 @@ int main(int argc, char** argv)
GenericList pieces = { 0, NULL, NULL };
- transformTexture(&texture, 0, 200.0, 0.00);
+ transformTexture(&texture, 0, screen.h / 3.0, 0.00);
// Main loop
while (!done) {
@@ -83,16 +83,20 @@ int main(int argc, char** argv)
useProgram(textureProgram);
CHECK_GL();
- if(back.y < (back.height - screen.h) / 2.0) {
- transformTexture(&back, 0, 1, 0);
+
+ float background_bottom_position = (back.height - screen.h) / 2.0;
+ float floor_position = -((screen.h / 2.0) -30 + 2 * (background_bottom_position - back.y));
+
+ if(back.y < background_bottom_position) {
+ transformTexture(&back, 0, 4, 0);
transformTexture(&texture, 0, 0, 0.01);
}
- else if(texture.y > -((screen.h / 2.0) -30)) {
- transformTexture(&texture, 0, -3, 0);
+ else if(texture.y > floor_position) {
+ transformTexture(&texture, 0, -4, 0);
transformTexture(&texture, 0, 0, 0.01);
}
- drawTexture(&back, 0, 0, 0);
+ drawTexture(&back, 0, 0, 0);
drawTexture(&texture, 0, 0, 0);
CHECK_GL();
@@ -148,14 +152,14 @@ int main(int argc, char** argv)
int nbPoints = 0;
if(nbPoints = find_intersect_points(&texture, &line, points)) {
- useProgram(pointProgram);
- drawLines(points, nbPoints);
if(nbPoints > 1 && lastCut < frames) {
+ useProgram(pointProgram);
+ drawLines(points, nbPoints);
lastCut = frames + 5;
- struct TextureInfos * texture1 = malloc(sizeof(struct TextureInfos));
- struct TextureInfos * texture2 = malloc(sizeof(struct TextureInfos));
+ TextureInfos * texture1 = malloc(sizeof(TextureInfos));
+ TextureInfos * texture2 = malloc(sizeof(TextureInfos));
split_vertex(&texture, &line, texture1, texture2);
@@ -177,9 +181,9 @@ int main(int argc, char** argv)
drawLines(points, nbPoints);
}
- struct TextureInfos * myTexture;
+ TextureInfos * myTexture;
for(el = pieces.first; el != NULL; el=el->next) {
- myTexture = (struct TextureInfos *) el->data;
+ myTexture = (TextureInfos *) el->data;
// TODO: free and cleanup
if(myTexture->y < -screen.h) {
removeFromList(&pieces, el);
@@ -194,8 +198,8 @@ int main(int argc, char** argv)
lastCut = frames + 5;
- struct TextureInfos * texture1 = malloc(sizeof(struct TextureInfos));
- struct TextureInfos * texture2 = malloc(sizeof(struct TextureInfos));
+ TextureInfos * texture1 = malloc(sizeof(TextureInfos));
+ TextureInfos * texture2 = malloc(sizeof(TextureInfos));
split_vertex(myTexture, &line, texture1, texture2);
@@ -208,13 +212,19 @@ int main(int argc, char** argv)
texture1->vy = -2.0;
texture2->vy = -2.0;
- texture1->vr = 0.01;
- texture2->vr = -0.01;
+ texture1->vr = 0.02;
+ texture2->vr = -0.02;
removeFromList(&pieces, el);
}
}
+ if(myTexture->y < floor_position) {
+ myTexture->vy = -myTexture->vy / 2.0;
+ myTexture->vx = 5 * myTexture->vx;
+ myTexture->vr = 2 * myTexture->vr;
+ }
+
// gravity
myTexture->vy = myTexture->vy - 0.15;

0 comments on commit cc03603

Please sign in to comment.