I've tried to port ToyShader ( see http://projects.autonomy.net.au/ai/browser/POC/OpenGL/TimLambertsToys/ToyShader.java?rev=) to JOGL2. It all seems to work except as follows:
- MacBook Pro - works perfectly - Mac Pro - textures displayed incorrectly The main difference between these two is that the MacBook has an Nvidia graphics card, the Mac Pro has ATI. Otherwise, - the exact same JOGL2 library files are used on each - the exact same Netbeans project is used on each to compile and run I'm reluctant to report this as a bug, as I may have done something wrong in my porting. I'd like someone to have a look at the code first, and see if there's an obvious mistake, before I report a bug. Also, the issue probably needs stripping down to essentials for a bug report. Here's the code for the main class, which is the one dealing with textures. package org.yourorghere; /** * Toy plaything for me to learn JOGL/OpenGL * See effects of different OpneGL settings and shaders */ import java.awt.event.*; import javax.swing.*; import java.util.*; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLEventListener; import javax.media.opengl.GLProfile; import javax.media.opengl.awt.GLCanvas; import javax.media.opengl.GL2; import com.jogamp.opengl.util.FPSAnimator; import com.jogamp.opengl.util.texture.*; import java.io.*; import java.nio.*; public class ToyShader2 extends JFrame implements GLEventListener, KeyListener { ShapeManager shapeManager; FPSAnimator animator; trackball ball = new trackball(); int aWidth = 1000; int aHeight = 1000; JCheckBoxMenuItem wireframe; JCheckBoxMenuItem specular; JCheckBoxMenuItem headLight; JCheckBoxMenuItem directionalLight; JCheckBoxMenuItem smooth; JCheckBoxMenuItem backFaceCull; JCheckBoxMenuItem zBuffer; JCheckBoxMenuItem twoSided; JCheckBoxMenuItem useShader; JCheckBoxMenuItem useTexture; JRadioButtonMenuItem[] levelItems, shaderItems, textureItems; //associates shader names with programs Map<String, Integer> programs = new HashMap<String, Integer>(); String shader; //name of current shader static final String shaderDir = "shaders"; //associates texture names with Textures Map<String, Texture> textures = new HashMap<String, Texture>(); String texture; //name of current texture static final String textureDir = "textures"; private float time = 0.0f; // keeps track of time -- passed to shaders private int timeLoc; // location of time variable public static void main(String[] args) { ToyShader2 t = new ToyShader2(); //exit if frame's close box is clicked t.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent e) { System.exit(0); } public void windowClosing(WindowEvent e) { windowClosed(e); } }); } int level; /* These functions are "callbacks" for events we are not interested in */ public void keyTyped(KeyEvent evt) { } public void keyReleased(KeyEvent evt) { } public ToyShader2() { super("ToyShader"); GLProfile glp = GLProfile.getDefault(); // Specifies a set of OpenGL capabilities, based on your profile. GLCapabilities caps = new GLCapabilities(glp); GLCanvas glc = new GLCanvas(caps); add("Center", glc); glc.setSize(aWidth, aHeight); JPopupMenu.setDefaultLightWeightPopupEnabled(false); //so menus appear above GLCanvas JMenuBar menubar = new JMenuBar(); setJMenuBar(menubar); shapeManager = new ShapeManager(); menubar.add(shapeManager.getMenu()); JMenu options = new JMenu("Options"); menubar.add(options); wireframe = new JCheckBoxMenuItem("Wireframe"); options.add(wireframe); headLight = new JCheckBoxMenuItem("Head Light"); options.add(headLight); headLight.setSelected(true); directionalLight = new JCheckBoxMenuItem("Directional Light"); options.add(directionalLight); specular = new JCheckBoxMenuItem("Specular Lighting"); options.add(specular); twoSided = new JCheckBoxMenuItem("Two-sided Lighting"); options.add(twoSided); backFaceCull = new JCheckBoxMenuItem("Back-face Cull"); options.add(backFaceCull); zBuffer = new JCheckBoxMenuItem("Use Z Buffer"); options.add(zBuffer); zBuffer.setSelected(true); smooth = new JCheckBoxMenuItem("Smooth Shading"); options.add(smooth); useShader = new JCheckBoxMenuItem("Use Shader"); options.add(useShader); useTexture = new JCheckBoxMenuItem("Use Texture"); options.add(useTexture); JMenu levels = new JMenu("Level"); ButtonGroup lbg = new ButtonGroup(); levelItems = new JRadioButtonMenuItem[7]; for (int i = 0; i < levelItems.length; i++) { levelItems[i] = new JRadioButtonMenuItem(i + ""); levels.add(levelItems[i]); lbg.add(levelItems[i]); levelItems[i].addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { level = Integer.parseInt(e.getActionCommand()); } }); } level = 2; levelItems[level].setSelected(true); menubar.add(levels); String[] names = ShaderUtil.listShaders(shaderDir); JMenu shaders = new JMenu("Shader"); ButtonGroup sbg = new ButtonGroup(); shaderItems = new JRadioButtonMenuItem[names.length]; if (names != null) { for (int i = 0; i < names.length; i++) { // strip off ".vert" suffix String thisname = names[i].substring(0, names[i].length() - 5); shaderItems[i] = new JRadioButtonMenuItem(thisname); shaders.add(shaderItems[i]); sbg.add(shaderItems[i]); shaderItems[i].addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { shader = e.getActionCommand(); } }); } } shaderItems[0].setSelected(true); shader = shaderItems[0].getActionCommand(); menubar.add(shaders); //texture menu -- we look for .png files in the texture directory. File dir = new File(textureDir); names = dir.list(new FilenameFilter() { public boolean accept(File dir, String name) { String lowname = name.toLowerCase(); return lowname.endsWith(".png") || lowname.endsWith(".jpg"); } }); JMenu textures = new JMenu("Texture"); ButtonGroup tbg = new ButtonGroup(); textureItems = new JRadioButtonMenuItem[names.length]; if (names != null) { for (int i = 0; i < names.length; i++) { textureItems[i] = new JRadioButtonMenuItem(names[i]); textures.add(textureItems[i]); tbg.add(textureItems[i]); textureItems[i].addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { texture = e.getActionCommand(); } }); } } textureItems[0].setSelected(true); texture = textureItems[0].getActionCommand(); menubar.add(textures); ball.listen(glc); glc.addGLEventListener(this); glc.addKeyListener(this); addKeyListener(this); animator = new FPSAnimator(glc, 100); //animate at 30 fps animator.start(); pack(); //work out sizes of all Components setVisible(true); } public void init(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); gl.glClearColor(0.2f, 0.3f, 0.2f, 1.0f); } public void keyPressed(KeyEvent evt) { if (evt.getKeyChar() == 'q') { animator.stop(); System.exit(0); } if (evt.getKeyChar() == 's') { specular.setSelected(!specular.isSelected()); //toggle } if (evt.getKeyChar() == 'r') { smooth.setSelected(!smooth.isSelected()); //toggle } if (evt.getKeyChar() == 'l') { twoSided.setSelected(!twoSided.isSelected()); //toggle } if (evt.getKeyChar() == '+' && level < levelItems.length - 1) { levelItems[++level].setSelected(true); } if (evt.getKeyChar() == '-' && level > 0) { levelItems[--level].setSelected(true); } } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { GL2 gl = drawable.getGL().getGL2(); gl.glViewport(x, y, width, height); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrtho(-2, 2, -2, 2, -5, 10); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); gl.glEnable(GL2.GL_AUTO_NORMAL); aWidth = width; aHeight = height; } public void display(GLAutoDrawable drawable) { float[] teapotMat = {0.6f, 0.6f, 0.6f, 1.0f}; float[] teapotSpec = {0.8f, 0.8f, 0.8f, 1.0f}; float[] zero = {0.0f, 0.0f, 0.0f, 1.0f}; GL2 gl = drawable.getGL().getGL2(); gl.glShadeModel(smooth.isSelected() ? GL2.GL_SMOOTH : GL2.GL_FLAT); gl.glLightModeli(GL2.GL_LIGHT_MODEL_TWO_SIDE, twoSided.isSelected() ? 1 : 0); if (zBuffer.isSelected()) { gl.glEnable(GL2.GL_DEPTH_TEST); } else { gl.glDisable(GL2.GL_DEPTH_TEST); } if (backFaceCull.isSelected()) { gl.glEnable(GL2.GL_CULL_FACE); } else { gl.glDisable(GL2.GL_CULL_FACE); } gl.glClear(GL2.GL_DEPTH_BUFFER_BIT | GL2.GL_COLOR_BUFFER_BIT); // gl.glColor3f(1.0f, 1.0f, 1.0f); float[] hlightpos = {0.0f, 0.0f, 1.0f, 0.0f}; gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, hlightpos, 0); gl.glEnable(GL2.GL_LIGHTING); if (headLight.isSelected()) { gl.glEnable(GL2.GL_LIGHT0); } else { gl.glDisable(GL2.GL_LIGHT0); } gl.glEnable(GL2.GL_NORMALIZE); //scale normals to have length 1 gl.glPushMatrix(); gl.glTranslatef(0.0f, 0.0f, -5.0f); gl.glMultMatrixf(ball.getRotMatrix(), 0); float[] dlightpos = {1.0f, 1.0f, 1.0f, 0.0f}; gl.glLightfv(GL2.GL_LIGHT1, GL2.GL_POSITION, dlightpos, 0); float[] dcolour = {0.6f, 0.6f, 0.6f, 0.0f}; gl.glLightfv(GL2.GL_LIGHT1, GL2.GL_DIFFUSE, dcolour, 0); gl.glLightfv(GL2.GL_LIGHT1, GL2.GL_SPECULAR, dcolour, 0); if (directionalLight.isSelected()) { gl.glEnable(GL2.GL_LIGHT1); } else { gl.glDisable(GL2.GL_LIGHT1); } gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_AMBIENT_AND_DIFFUSE, teapotMat, 0); if (specular.isSelected()) { gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_SPECULAR, teapotSpec, 0); gl.glMateriali(GL2.GL_FRONT, GL2.GL_SHININESS, 80); } else { gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_SPECULAR, zero, 0); gl.glMateriali(GL2.GL_FRONT, GL2.GL_SHININESS, 0); } if (wireframe.isSelected()) { gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_LINE); } else { gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_FILL); } if (useShader.isSelected()) { //use vertex and fragment shaders Integer programObject = programs.get(shader); if (programObject == null) { //need to load shaders into opengl int program = ShaderUtil.makeShaders(gl, shaderDir, shader); timeLoc = gl.glGetUniformLocation(program, "time"); programObject = new Integer(program); programs.put(shader, programObject); } gl.glUseProgram(programObject.intValue()); //tell shaders the time gl.glUniform1f(timeLoc, time); time += 1; } else { if (gl.isFunctionAvailable("glUseProgram")) { gl.glUseProgram(0); } } if (useTexture.isSelected()) { //apply specular lighting after texturing gl.glLightModeli(GL2.GL_LIGHT_MODEL_COLOR_CONTROL, GL2.GL_SEPARATE_SPECULAR_COLOR); //enable texturing gl.glEnable(GL2.GL_TEXTURE_2D); Texture tex = textures.get(texture); if (tex == null) { //need to load texture tex = loadTexture(textureDir + File.separator + texture); textures.put(texture, tex); } tex.enable(); gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT); gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT); gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_MODULATE); gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR); gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR_MIPMAP_LINEAR); tex.bind(); } else { gl.glDisable(GL2.GL_TEXTURE_2D); } shapeManager.display(gl, level, wireframe.isSelected()); gl.glPopMatrix(); } /** This method handles things if display depth changes */ public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { } public void dispose(GLAutoDrawable drawable) { } /** Load a texture from a file */ Texture loadTexture(String filename) { Texture texture = null; try { texture = TextureIO.newTexture(new File(filename), true); } catch (Exception e) { e.printStackTrace(); } return (texture); } } |
Administrator
|
How are the textures incorrect? Are the colors scrambled but the image is correctly shaped? The image is deformed, but colors correct? The exact type of image problem might help narrow down what's wrong.
|
The 3D geometry is always correct. In some cases no texture is applied at all. In other cases, the basic colour of the texture seems right at the largest scale, but in detail it is wrong. Sometimes you can even get the correct texture, at least for some of the textures. What actually happens is history dependent - if you start the program up and try different menu items in different orders, before going to the same final setting, the results can be different.
|
One further point. When I have the "basic color OK but not the texture in detail" problem, deselecting the Use Texture menu does not always remove the basic colour from the object.
|
Administrator
|
In reply to this post by Ralph Martin
On Thursday, February 24, 2011 11:19:20 Ralph Martin [via jogamp] wrote:
> > I've tried to port ToyShader ( see > http://projects.autonomy.net.au/ai/browser/POC/OpenGL/TimLambertsToys/ToyShader.java?rev=) > to JOGL2. It all seems to work except as follows: > > - MacBook Pro - works perfectly > - Mac Pro - textures displayed incorrectly > > The main difference between these two is that the MacBook has an Nvidia > graphics card, the Mac Pro has ATI. Otherwise, > - the exact same JOGL2 library files are used on each > - the exact same Netbeans project is used on each to compile and run > > I'm reluctant to report this as a bug, as I may have done something wrong in > my porting. I'd like someone to have a look at the code first, and see if > there's an obvious mistake, before I report a bug. Also, the issue probably > needs stripping down to essentials for a bug report. > > Here's the code for the main class, which is the one dealing with textures. > as you mentioned in your followup emails, maybe a texture use problem. can you fork jogl-demos and just add it there, maybe under: ../jogl-demos/src/demos/glsl/toyshader/ (Maybe a GL2 in the files when you use it, just to mark it ..) Then I would add a trace and debug pipeline like: public void init(GLAutoDrawable drawable) { GL _gl = drawable.getGL(); _gl = _gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Debug", null, _gl, null) ); _gl = _gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", null, _gl, new Object[] { System.err } ) ); ... } plus then we can more easily test you thing on other machines (with AMD GPUs). ~Sven > > package org.yourorghere; > > /** > * Toy plaything for me to learn JOGL/OpenGL > * See effects of different OpneGL settings and shaders > */ > > import java.awt.event.*; > import javax.swing.*; > import java.util.*; > import javax.media.opengl.GLAutoDrawable; > import javax.media.opengl.GLCapabilities; > import javax.media.opengl.GLEventListener; > import javax.media.opengl.GLProfile; > import javax.media.opengl.awt.GLCanvas; > import javax.media.opengl.GL2; > import com.jogamp.opengl.util.FPSAnimator; > import com.jogamp.opengl.util.texture.*; > import java.io.*; > import java.nio.*; > > public class ToyShader2 extends JFrame > implements GLEventListener, KeyListener { > > ShapeManager shapeManager; > FPSAnimator animator; > trackball ball = new trackball(); > int aWidth = 1000; > int aHeight = 1000; > JCheckBoxMenuItem wireframe; > JCheckBoxMenuItem specular; > JCheckBoxMenuItem headLight; > JCheckBoxMenuItem directionalLight; > JCheckBoxMenuItem smooth; > JCheckBoxMenuItem backFaceCull; > JCheckBoxMenuItem zBuffer; > JCheckBoxMenuItem twoSided; > JCheckBoxMenuItem useShader; > JCheckBoxMenuItem useTexture; > JRadioButtonMenuItem[] levelItems, shaderItems, textureItems; > //associates shader names with programs > Map<String, Integer> programs = new HashMap<String, Integer>(); > String shader; //name of current shader > static final String shaderDir = "shaders"; > //associates texture names with Textures > Map<String, Texture> textures = new HashMap<String, Texture>(); > String texture; //name of current texture > static final String textureDir = "textures"; > private float time = 0.0f; // keeps track of time -- passed to shaders > private int timeLoc; // location of time variable > > public static void main(String[] args) { > ToyShader2 t = new ToyShader2(); > //exit if frame's close box is clicked > t.addWindowListener(new WindowAdapter() { > > public void windowClosed(WindowEvent e) { > System.exit(0); > } > > public void windowClosing(WindowEvent e) { > windowClosed(e); > } > }); > } > int level; > > > /* These functions are "callbacks" for events we are > not interested in > */ > public void keyTyped(KeyEvent evt) { > } > > public void keyReleased(KeyEvent evt) { > } > > public ToyShader2() { > super("ToyShader"); > > GLProfile glp = GLProfile.getDefault(); > // Specifies a set of OpenGL capabilities, based on your profile. > GLCapabilities caps = new GLCapabilities(glp); > GLCanvas glc = new GLCanvas(caps); > > add("Center", glc); > glc.setSize(aWidth, aHeight); > > JPopupMenu.setDefaultLightWeightPopupEnabled(false); //so menus > appear above GLCanvas > > JMenuBar menubar = new JMenuBar(); > setJMenuBar(menubar); > > shapeManager = new ShapeManager(); > menubar.add(shapeManager.getMenu()); > > JMenu options = new JMenu("Options"); > menubar.add(options); > wireframe = new JCheckBoxMenuItem("Wireframe"); > options.add(wireframe); > headLight = new JCheckBoxMenuItem("Head Light"); > options.add(headLight); > headLight.setSelected(true); > directionalLight = new JCheckBoxMenuItem("Directional Light"); > options.add(directionalLight); > specular = new JCheckBoxMenuItem("Specular Lighting"); > options.add(specular); > twoSided = new JCheckBoxMenuItem("Two-sided Lighting"); > options.add(twoSided); > backFaceCull = new JCheckBoxMenuItem("Back-face Cull"); > options.add(backFaceCull); > zBuffer = new JCheckBoxMenuItem("Use Z Buffer"); > options.add(zBuffer); > zBuffer.setSelected(true); > smooth = new JCheckBoxMenuItem("Smooth Shading"); > options.add(smooth); > useShader = new JCheckBoxMenuItem("Use Shader"); > options.add(useShader); > useTexture = new JCheckBoxMenuItem("Use Texture"); > options.add(useTexture); > > JMenu levels = new JMenu("Level"); > ButtonGroup lbg = new ButtonGroup(); > levelItems = new JRadioButtonMenuItem[7]; > for (int i = 0; i < levelItems.length; i++) { > levelItems[i] = new JRadioButtonMenuItem(i + ""); > levels.add(levelItems[i]); > lbg.add(levelItems[i]); > levelItems[i].addActionListener(new ActionListener() { > > public void actionPerformed(ActionEvent e) { > level = Integer.parseInt(e.getActionCommand()); > } > }); > } > level = 2; > levelItems[level].setSelected(true); > menubar.add(levels); > > String[] names = ShaderUtil.listShaders(shaderDir); > JMenu shaders = new JMenu("Shader"); > ButtonGroup sbg = new ButtonGroup(); > shaderItems = new JRadioButtonMenuItem[names.length]; > if (names != null) { > for (int i = 0; i < names.length; i++) { > // strip off ".vert" suffix > String thisname = names[i].substring(0, names[i].length() - > 5); > shaderItems[i] = new JRadioButtonMenuItem(thisname); > shaders.add(shaderItems[i]); > sbg.add(shaderItems[i]); > shaderItems[i].addActionListener(new ActionListener() { > > public void actionPerformed(ActionEvent e) { > shader = e.getActionCommand(); > } > }); > } > } > shaderItems[0].setSelected(true); > shader = shaderItems[0].getActionCommand(); > menubar.add(shaders); > > //texture menu -- we look for .png files in the texture directory. > File dir = new File(textureDir); > names = dir.list(new FilenameFilter() { > > public boolean accept(File dir, String name) { > String lowname = name.toLowerCase(); > return lowname.endsWith(".png") || lowname.endsWith(".jpg"); > } > }); > JMenu textures = new JMenu("Texture"); > ButtonGroup tbg = new ButtonGroup(); > textureItems = new JRadioButtonMenuItem[names.length]; > if (names != null) { > for (int i = 0; i < names.length; i++) { > textureItems[i] = new JRadioButtonMenuItem(names[i]); > textures.add(textureItems[i]); > tbg.add(textureItems[i]); > textureItems[i].addActionListener(new ActionListener() { > > public void actionPerformed(ActionEvent e) { > texture = e.getActionCommand(); > } > }); > } > } > textureItems[0].setSelected(true); > texture = textureItems[0].getActionCommand(); > menubar.add(textures); > > > ball.listen(glc); > glc.addGLEventListener(this); > glc.addKeyListener(this); > addKeyListener(this); > animator = new FPSAnimator(glc, 100); //animate at 30 fps > animator.start(); > pack(); //work out sizes of all Components > setVisible(true); > } > > public void init(GLAutoDrawable drawable) { > GL2 gl = drawable.getGL().getGL2(); > gl.glClearColor(0.2f, 0.3f, 0.2f, 1.0f); > > } > > public void keyPressed(KeyEvent evt) { > if (evt.getKeyChar() == 'q') { > animator.stop(); > System.exit(0); > } > if (evt.getKeyChar() == 's') { > specular.setSelected(!specular.isSelected()); //toggle > } > if (evt.getKeyChar() == 'r') { > smooth.setSelected(!smooth.isSelected()); //toggle > } > if (evt.getKeyChar() == 'l') { > twoSided.setSelected(!twoSided.isSelected()); //toggle > } > if (evt.getKeyChar() == '+' && level < levelItems.length - 1) { > levelItems[++level].setSelected(true); > } > > if (evt.getKeyChar() == '-' && level > 0) { > levelItems[--level].setSelected(true); > } > > } > > public void reshape(GLAutoDrawable drawable, int x, int y, int width, > int height) { > GL2 gl = drawable.getGL().getGL2(); > gl.glViewport(x, y, width, height); > gl.glMatrixMode(GL2.GL_PROJECTION); > gl.glLoadIdentity(); > gl.glOrtho(-2, 2, -2, 2, -5, 10); > gl.glMatrixMode(GL2.GL_MODELVIEW); > gl.glLoadIdentity(); > gl.glEnable(GL2.GL_AUTO_NORMAL); > aWidth = width; > aHeight = height; > > } > > public void display(GLAutoDrawable drawable) { > float[] teapotMat = {0.6f, 0.6f, 0.6f, 1.0f}; > float[] teapotSpec = {0.8f, 0.8f, 0.8f, 1.0f}; > float[] zero = {0.0f, 0.0f, 0.0f, 1.0f}; > > GL2 gl = drawable.getGL().getGL2(); > gl.glShadeModel(smooth.isSelected() ? GL2.GL_SMOOTH : GL2.GL_FLAT); > gl.glLightModeli(GL2.GL_LIGHT_MODEL_TWO_SIDE, twoSided.isSelected() > ? 1 : 0); > > if (zBuffer.isSelected()) { > gl.glEnable(GL2.GL_DEPTH_TEST); > } else { > gl.glDisable(GL2.GL_DEPTH_TEST); > } > if (backFaceCull.isSelected()) { > gl.glEnable(GL2.GL_CULL_FACE); > } else { > gl.glDisable(GL2.GL_CULL_FACE); > } > > gl.glClear(GL2.GL_DEPTH_BUFFER_BIT | GL2.GL_COLOR_BUFFER_BIT); > // gl.glColor3f(1.0f, 1.0f, 1.0f); > float[] hlightpos = {0.0f, 0.0f, 1.0f, 0.0f}; > gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, hlightpos, 0); > gl.glEnable(GL2.GL_LIGHTING); > if (headLight.isSelected()) { > gl.glEnable(GL2.GL_LIGHT0); > } else { > gl.glDisable(GL2.GL_LIGHT0); > } > gl.glEnable(GL2.GL_NORMALIZE); //scale normals to have length 1 > > gl.glPushMatrix(); > gl.glTranslatef(0.0f, 0.0f, -5.0f); > gl.glMultMatrixf(ball.getRotMatrix(), 0); > float[] dlightpos = {1.0f, 1.0f, 1.0f, 0.0f}; > gl.glLightfv(GL2.GL_LIGHT1, GL2.GL_POSITION, dlightpos, 0); > float[] dcolour = {0.6f, 0.6f, 0.6f, 0.0f}; > gl.glLightfv(GL2.GL_LIGHT1, GL2.GL_DIFFUSE, dcolour, 0); > gl.glLightfv(GL2.GL_LIGHT1, GL2.GL_SPECULAR, dcolour, 0); > if (directionalLight.isSelected()) { > gl.glEnable(GL2.GL_LIGHT1); > } else { > gl.glDisable(GL2.GL_LIGHT1); > } > gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_AMBIENT_AND_DIFFUSE, > teapotMat, 0); > if (specular.isSelected()) { > gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_SPECULAR, teapotSpec, 0); > gl.glMateriali(GL2.GL_FRONT, GL2.GL_SHININESS, 80); > } else { > gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_SPECULAR, zero, 0); > gl.glMateriali(GL2.GL_FRONT, GL2.GL_SHININESS, 0); > } > if (wireframe.isSelected()) { > gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_LINE); > } else { > gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_FILL); > } > > > if (useShader.isSelected()) { > //use vertex and fragment shaders > Integer programObject = programs.get(shader); > if (programObject == null) { //need to load shaders into opengl > int program = ShaderUtil.makeShaders(gl, shaderDir, shader); > timeLoc = gl.glGetUniformLocation(program, "time"); > programObject = new Integer(program); > programs.put(shader, programObject); > } > gl.glUseProgram(programObject.intValue()); > //tell shaders the time > gl.glUniform1f(timeLoc, time); > time += 1; > } else { > if (gl.isFunctionAvailable("glUseProgram")) { > gl.glUseProgram(0); > } > } > > if (useTexture.isSelected()) { > //apply specular lighting after texturing > gl.glLightModeli(GL2.GL_LIGHT_MODEL_COLOR_CONTROL, > GL2.GL_SEPARATE_SPECULAR_COLOR); > //enable texturing > gl.glEnable(GL2.GL_TEXTURE_2D); > Texture tex = textures.get(texture); > if (tex == null) { //need to load texture > tex = loadTexture(textureDir + File.separator + texture); > textures.put(texture, tex); > } > tex.enable(); > gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S, > GL2.GL_REPEAT); > gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_T, > GL2.GL_REPEAT); > gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, > GL2.GL_MODULATE); > gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, > GL2.GL_LINEAR); > gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, > GL2.GL_LINEAR_MIPMAP_LINEAR); > tex.bind(); > } else { > gl.glDisable(GL2.GL_TEXTURE_2D); > } > > shapeManager.display(gl, level, wireframe.isSelected()); > > gl.glPopMatrix(); > } > > /** This method handles things if display depth changes */ > public void displayChanged(GLAutoDrawable drawable, > boolean modeChanged, > boolean deviceChanged) { > } > > public void dispose(GLAutoDrawable drawable) { > } > > /** Load a texture from a file */ > Texture loadTexture(String filename) { > Texture texture = null; > > try { > texture = TextureIO.newTexture(new File(filename), true); > } catch (Exception e) { > e.printStackTrace(); > } > return (texture); > } > } > > > _______________________________________________ > If you reply to this email, your message will be added to the discussion below: > http://forum.jogamp.org/Textures-program-works-on-one-machine-but-not-on-another-tp2566528p2566528.html > To start a new topic under jogl, email [hidden email] > To unsubscribe from jogl, visit health & wealth mailto:[hidden email] ; http://jausoft.com land : +49 (471) 4707742 ; cell: +49 (151) 28145941 Timezone CET: PST+9, EST+6, UTC+1 |
> can you fork jogl-demos and just add it there, maybe under:
> ../jogl-demos/src/demos/glsl/toyshader/ > (Maybe a GL2 in the files when you use it, just to mark it ..) Hmm, I dont really know how to do this - I'm just using jogl2 having downloaded the libraries. I do all my development in netbeans... I tried adding the tracing / debugging stuff to the display routine, but it generated so much output that the program was unresponsive, and unable to successfully make menu selections. I can certainly provide the rest of the source if that is useful, but all the texture handling stuff is done by the file I have already posted. |
Ah, read it more careful, and enabled tracing and debugging in "init" instead of "display". Worked OK on nVidia machine as before. Will need to wait till Monday till I can run the trace on the AMD machine at work. I'll post the trace stuff then.
|
Oh dear. When I added the debugging code on the machine with the AMD display, textures worked fine. Just to check, I went back to the version without the debugging code, and I again got incorrect behaviour. This is beginning to seem like a bug...
In summary public void init(GLAutoDrawable drawable) { GL _gl = drawable.getGL(); _gl = _gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Debug", null, _gl, null) ); _gl = _gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", null, _gl, new Object[] { System.err } ) ); GL2 gl= _gl.getGL2(); gl.glClearColor(0.2f, 0.3f, 0.2f, 1.0f); } works OK but public void init(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); gl.glClearColor(0.2f, 0.3f, 0.2f, 1.0f); } does not. |
Administrator
|
A bug report has been written about a similar problem (GLCanvas works only in debug mode since build 283), look at Bugzilla.
Julien Gouesse | Personal blog | Website
|
Administrator
|
Are you talking about https://jogamp.org/bugzilla/show_bug.cgi?id=469? This one crashes the JVM, but doesn't show the odd texture behavior that Ralph is seeing. |
In reply to this post by ralphrmartin
Is there anyone else here who uses netbeans for jogl 2, and has an AMD (ATI) graphics card? Maybe they can try running this and see if they get the same behaviour as me.
Alternatively, I suppose I should write this up as a bug. |
Turned debugging on, and got this, which I attach here just in case it shows something relevant.
JOGL/Java2D integration disabled GLProfile.init firstUIActionOnProcess: false, thread: main ----------------------------------------------------------------------------------------------------- Platform: Mac OS X 10.6.6 (os), x86_64 (arch) 16 cores Platform: littleEndian true, 32Bit false, a-ptr bit-size 64 Platform: Java 1.6.0_22, Java HotSpot(TM) 64-Bit Server VM, Apple Inc., http://www.apple.com/, is JavaSE: true ----------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------- Package: com.jogamp.common Extension Name: com.jogamp.common Specification Title: GlueGen Java Bindings Generator Specification Vendor: JogAmp Community Specification Version: 2.0 Implementation Title: GlueGen Run-Time Implementation Vendor: JogAmp Community Implementation Vendor ID: com.jogamp Implementation URL: http://jogamp.org/ Implementation Version: 2.0-b308-20110301 Implementation Branch: master Implementation Commit: 2557207469fe581cbc9d51861953cdc88f1e9715 ----------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------- Package: javax.media.nativewindow Extension Name: javax.media.nativewindow Specification Title: Native Window Interface API Specification Specification Vendor: JogAmp Community Specification Version: 2.0 Implementation Title: Native Window Interface Runtime Environment Implementation Vendor: JogAmp Community Implementation Vendor ID: com.jogamp Implementation URL: http://jogamp.org/ Implementation Version: 2.0-b338-20110301 Implementation Branch: master Implementation Commit: 65cd7d4be74539f7c6f5350ff38d02b44b5eb240 ----------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------- Package: javax.media.opengl Extension Name: javax.media.opengl Specification Title: Java Bindings for OpenGL API Specification Specification Vendor: JogAmp Community Specification Version: 2.0 Implementation Title: Java Bindings for OpenGL Runtime Environment Implementation Vendor: JogAmp Community Implementation Vendor ID: com.jogamp Implementation URL: http://jogamp.org/ Implementation Version: 2.0-b338-20110301 Implementation Branch: master Implementation Commit: 65cd7d4be74539f7c6f5350ff38d02b44b5eb240 ----------------------------------------------------------------------------------------------------- GLDrawableFactory.static - Native OS Factory for: MacOSX: jogamp.opengl.macosx.cgl.awt.MacOSXAWTCGLDrawableFactory java.lang.Throwable: Info: GLProfile.initProfilesForDevice: MacOSXGraphicsDevice[type MacOSX, connection decon, unitID 0, handle 0x0], isSet false at javax.media.opengl.GLProfile.initProfilesForDeviceImpl(GLProfile.java:1308) at javax.media.opengl.GLProfile.initProfilesForDevice(GLProfile.java:1298) at javax.media.opengl.GLProfile.initProfilesForDefaultDevices(GLProfile.java:1266) at javax.media.opengl.GLProfile.access$000(GLProfile.java:71) at javax.media.opengl.GLProfile$1.run(GLProfile.java:117) at java.security.AccessController.doPrivileged(Native Method) at javax.media.opengl.GLProfile.initSingleton(GLProfile.java:115) at javax.media.opengl.GLProfile.validateInitialization(GLProfile.java:1428) at javax.media.opengl.GLProfile.getProfileMap(GLProfile.java:1580) at javax.media.opengl.GLProfile.get(GLProfile.java:623) at javax.media.opengl.GLProfile.getDefault(GLProfile.java:480) at javax.media.opengl.GLProfile.getDefault(GLProfile.java:486) at org.yourorghere.ToyShader2.<init>(ToyShader2.java:83) at org.yourorghere.ToyShader2.main(ToyShader2.java:55) GLProfile.init map decon, desktopCtxUndef true, eglCtxUndef true GLProfile.init map GLProfile[GL4bc/GL4bc] on devide decon GLProfile.init map default GLProfile[GL4bc/GL4bc] on device decon GLProfile.init map GLProfile[GL3bc/GL3bc] on devide decon GLProfile.init map GLProfile[GL2/GL2] on devide decon GLProfile.init map GLProfile[GL2GL3/GL2] on devide decon GLProfile.init map GLProfile[GL4/GL4] on devide decon GLProfile.init map GLProfile[GL3/GL3] on devide decon GLProfile.init map GLProfile[GL2ES2/GL2] on devide decon GLProfile.init map *** no mapping for GLES2 on device decon GLProfile.init map GLProfile[GL2ES1/GL2] on devide decon GLProfile.init map *** no mapping for GLES1 on device decon GLProfile.initProfilesForDevice: MacOSXGraphicsDevice[type MacOSX, connection decon, unitID 0, handle 0x0]: desktop Shared Ctx false GLProfile.init map decon, desktopCtxUndef false, eglCtxUndef false GLProfile.init map *** no mapping for GL4bc on device decon GLProfile.init map *** no mapping for GL3bc on device decon GLProfile.init map GLProfile[GL2/GL2] on devide decon GLProfile.init map default GLProfile[GL2/GL2] on device decon GLProfile.init map GLProfile[GL2GL3/GL2] on devide decon GLProfile.init map *** no mapping for GL4 on device decon GLProfile.init map *** no mapping for GL3 on device decon GLProfile.init map GLProfile[GL2ES2/GL2] on devide decon GLProfile.init map *** no mapping for GLES2 on device decon GLProfile.init map GLProfile[GL2ES1/GL2] on devide decon GLProfile.init map *** no mapping for GLES1 on device decon main: !!! createContextARB: SET mappedVersionsAvailableSet MacOSX_decon_0 GLProfile.initProfilesForDevice: decon: added profile(s): desktop true, egl false GLProfile.initProfilesForDevice: decon: GLAvailability[Native[GL4bc false, GL4 false, GL3bc false, GL3 false, GL2 true[1.5 (compatibility profile, any, old)], GL2ES1 true, GLES1 false, GL2ES2 true, GLES2 false], Profiles[GLProfile[GL2ES2/GL2], GLProfile[GL2ES1/GL2], GLProfile[GL2/GL2], GLProfile[GL2/GL2], GLProfile[GL2GL3/GL2], , default GLProfile[GL2/GL2]]] GLProfile.dumpGLInfo: shared context n/a GLProfile.init isAWTAvailable true GLProfile.init has desktopFactory true GLProfile.init hasDesktopGL true GLProfile.init hasGL234Impl true GLProfile.init has eglFactory true GLProfile.init hasGLES1Impl false GLProfile.init hasGLES2Impl false GLProfile.init defaultDesktopDevice MacOSXGraphicsDevice[type MacOSX, connection decon, unitID 0, handle 0x0] GLProfile.init defaultEGLDevice EGLGraphicsDevice[type EGL, connection decon, unitID 0, handle 0x0] GLProfile.init defaultDevice MacOSXGraphicsDevice[type MacOSX, connection decon, unitID 0, handle 0x0] Animator add: 1009042595 - Thread[main,5,main] Info: GLCanvas display - skipped GL render, drawable not valid yet Info: GLCanvas display - skipped GL render, drawable not valid yet Info: GLCanvas display - skipped GL render, drawable not valid yet java.lang.Exception: main - Info: addNotify - start, bounds: java.awt.Rectangle[x=0,y=0,width=1000,height=1000] at javax.media.opengl.awt.GLCanvas.addNotify(GLCanvas.java:503) at java.awt.Container.addNotify(Container.java:2622) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2622) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2622) at javax.swing.JComponent.addNotify(JComponent.java:4685) at javax.swing.JRootPane.addNotify(JRootPane.java:739) at java.awt.Container.addNotify(Container.java:2622) at java.awt.Window.addNotify(Window.java:663) at java.awt.Frame.addNotify(Frame.java:470) at java.awt.Window.pack(Window.java:704) at org.yourorghere.ToyShader2.<init>(ToyShader2.java:201) at org.yourorghere.ToyShader2.main(ToyShader2.java:55) MacOSXAWTCGLGraphicsConfigurationFactory: got AWTGraphicsScreen[AWTGraphicsDevice[type AWT[subType null], connection \Display0, unitID 0, awtDevice CGraphicsDevice[screen=0], handle 0x0], idx 0] MacOSXAWTCGLGraphicsConfigurationFactory: made DefaultGraphicsScreen[MacOSXGraphicsDevice[type MacOSX, connection decon, unitID 0, handle 0x0], idx 0] Exception in thread "main" java.lang.NullPointerException at javax.media.opengl.awt.GLCanvas.toString(GLCanvas.java:748) at java.lang.String.valueOf(String.java:2826) at java.lang.StringBuilder.append(StringBuilder.java:115) at jogamp.nativewindow.jawt.JAWTWindow.toString(JAWTWindow.java:274) at java.lang.String.valueOf(String.java:2826) at java.lang.StringBuilder.append(StringBuilder.java:115) at jogamp.opengl.GLDrawableFactoryImpl.createGLDrawable(GLDrawableFactoryImpl.java:107) at javax.media.opengl.awt.GLCanvas.addNotify(GLCanvas.java:524) at java.awt.Container.addNotify(Container.java:2622) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2622) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2622) at javax.swing.JComponent.addNotify(JComponent.java:4685) at javax.swing.JRootPane.addNotify(JRootPane.java:739) at java.awt.Container.addNotify(Container.java:2622) at java.awt.Window.addNotify(Window.java:663) at java.awt.Frame.addNotify(Frame.java:470) at java.awt.Window.pack(Window.java:704) at org.yourorghere.ToyShader2.<init>(ToyShader2.java:201) at org.yourorghere.ToyShader2.main(ToyShader2.java:55) Info: GLCanvas display - skipped GL render, drawable not valid yet Info: GLCanvas display - skipped GL render, drawable not valid yet Info: GLCanvas display - skipped GL render, drawable not valid yet ... |
Administrator
|
In reply to this post by ralphrmartin
I can try it in NetBeans with an old ATI (Mobility Radeon x300) if you want. Just zip up your NetBeans project and post it here.
|
Administrator
|
Hmm, when I try to unzip it with Windows, I get an error saying the zip is invalid. 7zip turns it into a single file called ToyShader, when I assume it should be a directory full of stuff.
|
Strange. Perhaps the jogamp web server is sending it with the wrong filetype?
I just downloaded it and unzipped it OK on Windows 7. You'll find two folders in the archive, one called _MACOSX which you can safely ignore, and the other which is the ToyShader2 folder with the project in it. If it still doesn't work, email me at ralph@cs.cf.ac.uk and I will email you the project. Thanks for your interest. |
In reply to this post by Wade Walker
Strange. Perhaps the jogamp web server is sending it with the wrong filetype?
I just downloaded it and unzipped it OK on Windows 7. You'll find two folders in the archive, one called _MACOSX which you can safely ignore, and the other which is the ToyShader2 folder with the project in it. If it still doesn't work, email me at ralph@cs.cf.ac.uk and I will email you the project. Thanks for your interest. |
Administrator
|
In reply to this post by ralphrmartin
On Thursday, March 03, 2011 16:27:17 ralphrmartin [via jogamp] wrote:
> > Strange. Perhaps the jogamp web server is sending it with the wrong filetype? It's really nabble, we just fwd to it. ~Sven |
Administrator
|
In reply to this post by ralphrmartin
Weird -- I just tried it again, and it worked this time (though I had to re-create the NetBeans project because of some embedded MacOS path stuff that I couldn't figure out how to change within the NB GUI).
The ToyShader2 app works on my modern nvidia 8800 GTX in 64-bit Win 7, so this weekend I'll install NetBeans on my old computer and try the ATI Mobility Radeon x300. |
Administrator
|
OK, finally got it working on my ancient laptop with Mobility Radeon x300, Win XP 32. The textures that work look correct, but some of them don't show up at all (leather, earth, and tinfoil are the only ones that appear). The shaders don't do anything, but this is probably because the card is too old to support them.
In the process, I found what seems to be a bug with newer versions of JOGL 2 on ATI cards, where it causes a HotSpot crash. I'll report this on another thread, I think I saw someone else mention the same thing recently. |
Free forum by Nabble | Edit this page |