glEnable(GL_TEXTURE_2D); Does not feel like working.... :( - java

So, I'm trying to apply a texture to my quad.
So i wrote this line of code : (line 35 in Artist.java)
glEnable(GL_TEXTURE_2D);
Which gave me this error :
GL_TEXTURE_2D cannot be resolved to a variable
I have these imports : (Hitting CTRL+SHIFT+O did not do anything)
import static org.lwjgl.opengl.GL11.GL_MODELVIEW;
import static org.lwjgl.opengl.GL11.GL_PROJECTION;
import static org.lwjgl.opengl.GL11.GL_QUADS;
import static org.lwjgl.opengl.GL11.glBegin;
import static org.lwjgl.opengl.GL11.glEnd;
import static org.lwjgl.opengl.GL11.glLoadIdentity;
import static org.lwjgl.opengl.GL11.glMatrixMode;
import static org.lwjgl.opengl.GL11.glOrtho;
import static org.lwjgl.opengl.GL11.glVertex2f;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
I'm using Java, Eclipse, Mars. Anyone know why it won't work? :)

glEnable( GL_TEXTURE_2D) is a directive to the fixed-function
pipeline's shader generator that you want to include code to support
that texture unit
So if you use a modern opengl which has custom shaders, its option won't work ,and you won't need it.

For it to not error you need to import both GL_TEXTURE_2D and glEnable().
Like Sung Woo mentioned however, this function is deprecated and only needs to be used in the old OpenGL.

Related

Java class import issues. import java.awt.geom.Rectangle2D.Float not working

I am using the java.awt.geom library in Processing and specifically using the Rectangle2D.Float class.
When I use import java.awt.geom.Rectangle2D.Float I get an error when I try declaring Rectangle2D.Float buttonOne;, but if I use import java.awt.geom.Rectangle2D or import java.awt.geom.* the code works fine.
I am wondering why this is.
If you just drop the Rectangle2D from the Float it will work with the first import

LWJGL/opengl in eclipse

I cannot seem to import the opengl properly.
I am following this simple tutorial:
https://www.youtube.com/watch?v=ZKJC2cloIqc
As far as I understand, I have the correct jar and native files.
// I can import these
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
//I cannot however import this:
import org.lwjgl.LWJGLEXCEPTION;
//and gl methods such as this are not recognized:
glClear(GL_COLOR_BUFFER_BIT);
I am using eclipse, I also have netbeans and am debating getting the intelij IDE being used in this tutorial if it will make this work.
You didn't Import GL11 to use gl methods (or other versions for certain methods )
You can use a static import so you don't have to put GL11 in front of every method or anything else

Android Studio cannot find sun.awt.image package and import java.awt.color.ColorSpace

I am working in an Android project recently. Our project uses a computer vision library called boofcv:
http://boofcv.org/index.php?title=Main_Page
After importing the library source code into our project, I found that Android Studio cannot revolve symbols from sun.awt.image.* and java.awt.color.ColorSpace.
package boofcv.core.image;
import boofcv.struct.image.*;
import sun.awt.image.ByteInterleavedRaster;
import sun.awt.image.IntegerInterleavedRaster;
import sun.awt.image.ShortInterleavedRaster;
import javax.swing.*;
import java.awt.*;
import java.awt.color.ColorSpace;
import java.awt.image.*;
import java.lang.reflect.Array;
/**
* Functions for converting to and from {#link BufferedImage}.
*
* #author Peter Abeles
*/
public class ConvertBufferedImage {
......
But then I wrote a very simple test program and found that my jdk did contain those classes. my program:
import sun.awt.image.ByteInterleavedRaster;
import sun.awt.image.IntegerInterleavedRaster;
import sun.awt.image.ShortInterleavedRaster;
import javax.swing.*;
import java.awt.*;
import java.awt.color.ColorSpace;
import java.awt.image.*;
class test{
public static void main(String[] args) {
ByteInterleavedRaster b;
IntegerInterleavedRaster i;
ShortInterleavedRaster s;
ColorSpace c;
System.out.println("testing");
}
}
Did I miss some configuration or it is just the issue of Android Studio?
Any help is greatly appreciated.
Don't use the visualization package for anything on Android. It's based off on swing which isn't supported on Android. Use the android package in integration. It has similar functions for visualizing data.
https://github.com/lessthanoptimal/BoofAndroidDemo
that might be useful for you.

Static import - Netbeans error

The error, Netbeans gives me, is:
static import only from classes and interfaces
which is somehow strange for me, as this:
import org.lwjgl.opengl.GL11;
works fine while this:
import static org.lwjgl.opengl.GL11;
doesn't. Why is it not working for me?
BTW, GL11 is a class and I don't know why but Netbeans, when importing statically, thinks opengl is the class I want to import.
You wanna write:
import static org.lwjgl.opengl.GL11.*;
You are importing the members of the class, thus the * at the end.
Static import allows you to import static fields of other class. For example you can say
import static java.awt.Color.RED;
And then use RED in your class without mentioning class where it is defined.

Finding import static statements for Mockito constructs

I'm trying to crash through the brick wall between me and Mockito. I've torn my hair out over trying to get correct import static statements for Mockito stuff. You'd think someone would just throw up a table saying that anyInt() comes from org.mockito.Matchers and when() comes from org.mockito.Mockito, etc., but that would be too helpful to newcomers, no?
This sort of thing, especially when mixed in with myriad more import statements ending in asterisks, isn't always very helpful:
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
Yes, I know about and have been trying to use the Eclipse Window -> Preferences-> Java -> Editor-> Content Assist -> Favorites mechanism. It helps, but it doesn't hit the nail on the head.
Any answers to this question would be appreciated.
Many thanks,
Russ
Here's what I've been doing to cope with the situation.
I use global imports on a new test class.
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.mockito.Matchers.*;
When you are finished writing your test and need to commit, you just CTRL+SHIFT+O to organize the packages. For example, you may just be left with:
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Matchers.anyString;
This allows you to code away without getting 'stuck' trying to find the correct package to import.
The problem is that static imports from Hamcrest and Mockito have similar names, but return Matchers and real values, respectively.
One work-around is to simply copy the Hamcrest and/or Mockito classes and delete/rename the static functions so they are easier to remember and less show up in the auto complete. That's what I did.
Also, when using mocks, I try to avoid assertThat in favor other other assertions and verify, e.g.
assertEquals(1, 1);
verify(someMock).someMethod(eq(1));
instead of
assertThat(1, equalTo(1));
verify(someMock).someMethod(eq(1));
If you remove the classes from your Favorites in Eclipse, and type out the long name e.g. org.hamcrest.Matchers.equalTo and do CTRL+SHIFT+M to 'Add Import' then autocomplete will only show you Hamcrest matchers, not any Mockito matchers. And you can do this the other way so long as you don't mix matchers.
For is()
import static org.hamcrest.CoreMatchers.*;
For assertThat()
import static org.junit.Assert.*;
For when() and verify()
import static org.mockito.Mockito.*;
My imports
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.junit.Test;
And it works
import static org.mockito.Matchers.anyInt;
e.g.
when(listMock.get(anyInt())).thenReturn("stackoverflow");

Categories

Resources