Hi
I have managed to get the milkshape loader to load the 3d model(created in milkshape3d), and it was rendered correctly at my first attempt because i just made a simple sphere with no texture.
But when I try to use a model with a texture I get a strange error. The texture is a .bmp 128x128 size.
Heres the error: "
java.lang.IllegalArgumentException: Number of remaining buffer elements is 0, must be at least 4
at org.lwjgl.opengl.BufferChecks.checkBuffer(Unknown Source)
at org.lwjgl.opengl.BufferChecks.checkBuffer(Unknown Source)
at org.lwjgl.opengl.GL11.glMaterial(Unknown Source)
at najgl.model.ms3d.MilkshapeModel.draw(Unknown Source)
at Game.render(Unknown Source)
at Game.run(Unknown Source)
at Game.main(Unknown Source) "
I looked at the example in the najgl library to load a model in my game, and the Game.java file is based on the lwjgl example.., So because i use lwjgl 09 alpha i had to change many GL calls to GL11.GL etc.. in the najgl library but everything worked until i made a model with a texture. The texture is also put at the correct location in the filesystem.
Maybe theres something i missed in the setup of lwjgl because I used the easy setup of Game.java example from lwjgl09, and the example game in najgl uses lots of gl calls that i dont understand.
Maybe Its just something with the buffers.. ?
Here is the code of Game.java so you guys can take a look at what im doing.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
| import java.awt.Graphics2D; import java.awt.Image; import java.awt.geom.AffineTransform; import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.IntBuffer;
import najgl.model.Model; import najgl.model.ms3d.MilkshapeModel;
import org.lwjgl.Sys; import org.lwjgl.input.Keyboard; import org.lwjgl.openal.AL; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.Window; public class Game { public static final String GAME_TITLE = "My Game"; private static final int FRAMERATE = 60; private static boolean finished; private static final boolean WIREFRAME = false; private static final boolean ANIMATED = false; private static String modelFilename = "data/mysphere.txt"; private static Model model; private Game() {} public static void main(String[] args) { try { init(); run(); } catch (Exception e) { e.printStackTrace(System.err); Sys.alert(GAME_TITLE, "An error occured and the game will exit."); } finally { cleanup(); } } private static void init() throws Exception { Window.create(GAME_TITLE); Window.setVSyncEnabled(true); AL.create(); model = new MilkshapeModel(ANIMATED, WIREFRAME); model.load(modelFilename); if (WIREFRAME) { GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE); } else { GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glShadeModel(GL11.GL_SMOOTH); } GL11.glTranslatef(100.0f, 100.0f, 0.0f); GL11.glScalef(5.0f,5.0f,5.0f); }
private static void run() { while (!finished) { Window.update(); if (Window.isCloseRequested()) { finished = true; } else if (Window.isActive()) { logic(); render(); org.lwjgl.Display.sync(FRAMERATE); } else { try { Thread.sleep(100); } catch (InterruptedException e) { } logic(); if (Window.isVisible() || Window.isDirty()) { render(); } } } } private static void cleanup() { AL.destroy(); Window.destroy(); } private static void logic() { if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) { finished = true; } } private static void render() { GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT); model.draw();
} } |
