GL_ScreenShot_f
()
| 120 | * GL_ScreenShot_f |
| 121 | */ |
| 122 | public void GL_ScreenShot_f() { |
| 123 | StringBuffer sb = new StringBuffer(FS.getWriteDir() + "/scrshot/jake00.tga"); |
| 124 | FS.CreatePath(sb.toString()); |
| 125 | File file = new File(sb.toString()); |
| 126 | // find a valid file name |
| 127 | int i = 0; int offset = sb.length() - 6; |
| 128 | while (file.exists() && i++ < 100) { |
| 129 | sb.setCharAt(offset, (char) ((i/10) + '0')); |
| 130 | sb.setCharAt(offset + 1, (char) ((i%10) + '0')); |
| 131 | file = new File(sb.toString()); |
| 132 | } |
| 133 | if (i == 100) { |
| 134 | Com.Printf(Defines.PRINT_ALL, "Clean up your screenshots\n"); |
| 135 | return; |
| 136 | } |
| 137 | |
| 138 | try { |
| 139 | RandomAccessFile out = new RandomAccessFile(file, "rw"); |
| 140 | FileChannel ch = out.getChannel(); |
| 141 | int fileLength = TGA_HEADER_SIZE + vid.getWidth() * vid.getHeight() * 3; |
| 142 | out.setLength(fileLength); |
| 143 | MappedByteBuffer image = ch.map(FileChannel.MapMode.READ_WRITE, 0, |
| 144 | fileLength); |
| 145 | |
| 146 | // write the TGA header |
| 147 | image.put(0, (byte) 0).put(1, (byte) 0); |
| 148 | image.put(2, (byte) 2); // uncompressed type |
| 149 | image.put(12, (byte) (vid.getWidth() & 0xFF)); // vid.getWidth() |
| 150 | image.put(13, (byte) (vid.getWidth() >> 8)); // vid.getWidth() |
| 151 | image.put(14, (byte) (vid.getHeight() & 0xFF)); // vid.getHeight() |
| 152 | image.put(15, (byte) (vid.getHeight() >> 8)); // vid.getHeight() |
| 153 | image.put(16, (byte) 24); // pixel size |
| 154 | |
| 155 | // go to image data position |
| 156 | image.position(TGA_HEADER_SIZE); |
| 157 | |
| 158 | |
| 159 | // change pixel alignment for reading |
| 160 | if (vid.getWidth() % 4 != 0) { |
| 161 | gl.glPixelStorei(GL_PACK_ALIGNMENT, 1); |
| 162 | } |
| 163 | |
| 164 | // OpenGL 1.2+ supports the GL_BGR color format |
| 165 | // check the GL_VERSION to use the TARGA BGR order if possible |
| 166 | // e.g.: 1.5.2 NVIDIA 66.29 |
| 167 | if (gl_config.getOpenGLVersion() >= 1.2f) { |
| 168 | // read the BGR values into the image buffer |
| 169 | gl.glReadPixels(0, 0, vid.getWidth(), vid.getHeight(), GL_BGR, GL_UNSIGNED_BYTE, image); |
| 170 | } else { |
| 171 | // read the RGB values into the image buffer |
| 172 | gl.glReadPixels(0, 0, vid.getWidth(), vid.getHeight(), GL_RGB, GL_UNSIGNED_BYTE, image); |
| 173 | // flip RGB to BGR |
| 174 | byte tmp; |
| 175 | for (i = TGA_HEADER_SIZE; i < fileLength; i += 3) { |
| 176 | tmp = image.get(i); |
| 177 | image.put(i, image.get(i + 2)); |
| 178 | image.put(i + 2, tmp); |
| 179 | } |
nothing calls this directly
no test coverage detected