this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Added multitexture-blit test (from code by Mason Wheeler).

+178
+3
tests/CMakeLists.txt
··· 127 127 add_executable(renderer-test renderer/main.c) 128 128 target_link_libraries (renderer-test ${TEST_LIBS}) 129 129 130 + add_executable(multitexture-test multitexture-blit/main.c) 131 + target_link_libraries (multitexture-test ${TEST_LIBS}) 132 + 130 133 add_executable(video-test video/main.c) 131 134 target_link_libraries (video-test ${TEST_LIBS})
+175
tests/multitexture-blit/main.c
··· 1 + #include "SDL.h" 2 + #include "SDL_gpu.h" 3 + #include "common.h" 4 + 5 + #define VERT \ 6 + "#version 130\n" \ 7 + "in vec2 RPG_Vertex;\n" \ 8 + "in vec2 RPG_TexCoord;\n" \ 9 + "in vec2 RPG_TexCoord2;\n" \ 10 + "uniform mat4 RPG_ModelViewProjectionMatrix;\n" \ 11 + "out vec2 texCoord;\n" \ 12 + "out vec2 texCoord2;\n" \ 13 + "void main(void)\n" \ 14 + "{\n" \ 15 + " texCoord = vec2(RPG_TexCoord);\n" \ 16 + " texCoord2 = vec2(RPG_TexCoord2);\n" \ 17 + " gl_Position = RPG_ModelViewProjectionMatrix * vec4(RPG_Vertex, 0.0, 1.0);\n" \ 18 + "}" 19 + 20 + #define FRAG \ 21 + "#version 110\n" \ 22 + "uniform sampler2D texAlpha;\n" \ 23 + "uniform sampler2D texRGB;\n" \ 24 + "varying vec2 texCoord;\n" \ 25 + "varying vec2 texCoord2;\n" \ 26 + "void main()\n" \ 27 + "{\n" \ 28 + " float alpha = texture2D(texAlpha, texCoord).a;\n" \ 29 + " vec3 rgb = texture2D(texRGB, texCoord2).rgb;\n" \ 30 + " gl_FragColor = vec4(rgb, alpha);\n" \ 31 + "}" 32 + 33 + int main(int argc, char* argv[]) 34 + { 35 + GPU_Target* screen; 36 + 37 + screen = initialize_demo(argc, argv, 800, 600); 38 + if(screen == NULL) 39 + return 1; 40 + 41 + { 42 + Uint32 startTime; 43 + long frameCount; 44 + Uint8 done; 45 + SDL_Event event; 46 + 47 + 48 + float dt = 0.010f; 49 + 50 + #define MAX_SPRITES 50 51 + int numSprites = 1; 52 + 53 + float x[MAX_SPRITES]; 54 + float y[MAX_SPRITES]; 55 + float velx[MAX_SPRITES]; 56 + float vely[MAX_SPRITES]; 57 + int i; 58 + 59 + GPU_Image* image = GPU_LoadImage("data/test3.png"); 60 + if(image == NULL) 61 + return 2; 62 + GPU_Image* image2 = GPU_LoadImage("data/test4.bmp"); 63 + if(image2 == NULL) 64 + return 3; 65 + 66 + GPU_Image* images[2]; 67 + images[0] = image; 68 + images[1] = image2; 69 + 70 + GPU_Rect rects[2]; 71 + rects[0] = GPU_MakeRect(0, 0, image->w, image->h); 72 + rects[1] = GPU_MakeRect(0, 0, image2->w, image2->h); 73 + 74 + Uint32 vert = GPU_CompileShader(GPU_VERTEX_SHADER, VERT); 75 + Uint32 frag = GPU_CompileShader(GPU_FRAGMENT_SHADER, FRAG); 76 + 77 + Uint32 prog = GPU_LinkShaders(vert, frag); 78 + GPU_ShaderBlock block = GPU_LoadShaderBlock(prog, "RPG_Vertex", "RPG_TexCoord", NULL, "RPG_ModelViewProjectionMatrix"); 79 + GPU_ActivateShaderProgram(prog, &block); 80 + 81 + char* samplers[2] = {"texAlpha", "texRGB"}; 82 + char* texcoords[2] = {"RPG_TexCoord", "RPG_TexCoord2"}; 83 + GPU_MultitextureBlock block2 = GPU_LoadMultitextureBlock(2, samplers, texcoords); 84 + GPU_SetMultitextureBlock(&block2); 85 + 86 + GPU_SetSnapMode(image, GPU_SNAP_NONE); 87 + 88 + for(i = 0; i < MAX_SPRITES; i++) 89 + { 90 + x[i] = rand()%screen->w; 91 + y[i] = rand()%screen->h; 92 + velx[i] = 10 + rand()%screen->w/10; 93 + vely[i] = 10 + rand()%screen->h/10; 94 + } 95 + 96 + 97 + startTime = SDL_GetTicks(); 98 + frameCount = 0; 99 + 100 + done = 0; 101 + while(!done) 102 + { 103 + while(SDL_PollEvent(&event)) 104 + { 105 + if(event.type == SDL_QUIT) 106 + done = 1; 107 + else if(event.type == SDL_KEYDOWN) 108 + { 109 + if(event.key.keysym.sym == SDLK_ESCAPE) 110 + done = 1; 111 + else if(event.key.keysym.sym == SDLK_EQUALS || event.key.keysym.sym == SDLK_PLUS) 112 + { 113 + if(numSprites < MAX_SPRITES) 114 + numSprites++; 115 + } 116 + else if(event.key.keysym.sym == SDLK_MINUS) 117 + { 118 + if(numSprites > 0) 119 + numSprites--; 120 + } 121 + } 122 + } 123 + 124 + for(i = 0; i < numSprites; i++) 125 + { 126 + x[i] += velx[i]*dt; 127 + y[i] += vely[i]*dt; 128 + if(x[i] < 0) 129 + { 130 + x[i] = 0; 131 + velx[i] = -velx[i]; 132 + } 133 + else if(x[i]> screen->w) 134 + { 135 + x[i] = screen->w; 136 + velx[i] = -velx[i]; 137 + } 138 + 139 + if(y[i] < 0) 140 + { 141 + y[i] = 0; 142 + vely[i] = -vely[i]; 143 + } 144 + else if(y[i]> screen->h) 145 + { 146 + y[i] = screen->h; 147 + vely[i] = -vely[i]; 148 + } 149 + } 150 + 151 + GPU_Clear(screen); 152 + 153 + for(i = 0; i < numSprites; i++) 154 + { 155 + GPU_MultitextureBlit(images, rects, screen, x[i], y[i]); 156 + } 157 + 158 + GPU_Flip(screen); 159 + 160 + frameCount++; 161 + if(frameCount%500 == 0) 162 + printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); 163 + } 164 + 165 + printf("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime)); 166 + 167 + GPU_FreeImage(image); 168 + } 169 + 170 + GPU_Quit(); 171 + 172 + return 0; 173 + } 174 + 175 +