По какой-то причине размер окна всегда остается одинаковым, даже когда я изменяю ширину и высоту. Я думаю, что проблема связана с областью просмотра, так как видимая область в окне изменяется правильно, но всегда есть черная область в той части окна, которая не используется. Я, вероятно, объяснил это очень плохо, но любая помощь будет высоко ценится.
Я поставил скриншот окна ниже ..
public class DisplayExample
{
private int width = 800;
private int height = 600;
private int colourDepth = 32;
private String windowTitle = "My First Window";
public boolean closeRequested = false;
private boolean fullscreen = false;
private float rtri = 0.0f;
private float rquad = 0.0f;
public void start()
{
createWindow(windowTitle, width, height, colourDepth, fullscreen);
initGL();
while (!closeRequested)
{
pollInput();
updateLogic();
renderGL();
Display.update(); // flushes OpenGL pipeline and swaps back and
// front buffers. perhaps waits for v-sync.
}
cleanUp();
}
/**
* Initialise OpenGL
*/
private void initGL()
{
GL11.glViewport(0, 0, width, height);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluPerspective(45.0f, ((float) width / (float) height), 0.1f,
100.0f);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glShadeModel(GL11.GL_SMOOTH); // Smooth shading
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black background
GL11.glClearDepth(1.0f);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDepthFunc(GL11.GL_LEQUAL);
GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
}
/**
* Update Logic
*/
private void updateLogic()
{
}
/**
* Render OpenGL
*/
private void renderGL()
{
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); // Clear
// The
// Screen
// And
// The
// Depth
// Buffer
GL11.glLoadIdentity(); // Reset The View
GL11.glTranslatef(-1.5f, 0.0f, -6.0f); // Move Left 1.5 Units And Into
// The Screen 6.0
GL11.glRotatef(rtri, 0.0f, 1.0f, 0.0f);
GL11.glBegin(GL11.GL_TRIANGLES); // Drawing Using Triangles
GL11.glColor3f(1.0f, 0.0f, 0.0f);
GL11.glVertex3f(0.0f, 1.0f, 0.0f); // Top
GL11.glColor3f(0.0f, 1.0f, 0.0f);
GL11.glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left
GL11.glColor3f(0.0f, 0.0f, 1.0f);
GL11.glVertex3f(1.0f, -1.0f, 1.0f); // Bottom Right
GL11.glColor3f(1.0f, 0.0f, 0.0f);
GL11.glVertex3f(0.0f, 1.0f, 0.0f); // Top
GL11.glColor3f(0.0f, 0.0f, 1.0f);
GL11.glVertex3f(1.0f, -1.0f, 1.0f); // Bottom Left
GL11.glColor3f(0.0f, 1.0f, 0.0f);
GL11.glVertex3f(1.0f, -1.0f, -1.0f); // Bottom Right
GL11.glColor3f(1.0f, 0.0f, 0.0f);
GL11.glVertex3f(0.0f, 1.0f, 0.0f); // Top
GL11.glColor3f(0.0f, 0.0f, 1.0f);
GL11.glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Left
GL11.glColor3f(0.0f, 1.0f, 0.0f);
GL11.glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right
GL11.glColor3f(1.0f, 0.0f, 0.0f);
GL11.glVertex3f(0.0f, 1.0f, 0.0f); // Top
GL11.glColor3f(0.0f, 1.0f, 0.0f);
GL11.glVertex3f(1.0f, -1.0f, -1.0f); // Bottom Left
GL11.glColor3f(0.0f, 0.0f, 1.0f);
GL11.glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Right
GL11.glEnd(); // Finished Drawing The Triangle
GL11.glLoadIdentity(); // Reset The View
GL11.glTranslatef(1.5f, 0.0f, -2.5f); // Move Right 3 Units
GL11.glRotatef(rquad, 1.0f, 1.0f, 1.0f);
GL11.glBegin(GL11.GL_QUADS); // Draw A Quad
//TOP
GL11.glColor3f(0.0f, 1.0f, 0.0f);
GL11.glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left
GL11.glVertex3f(1.0f, 1.0f, -1.0f); // Top Right
GL11.glVertex3f(1.0f, 1.0f, 1.0f); // Bottom Right
GL11.glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left
//FRONT
GL11.glColor3f(1.0f, 0.5f, 0.0f);
GL11.glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left
GL11.glVertex3f(1.0f, 1.0f, 1.0f); // Top Right
GL11.glVertex3f(1.0f, -1.0f, 1.0f); // Bottom Right
GL11.glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left
//LEFT
GL11.glColor3f(1.0f, 0.0f, 0.0f);
GL11.glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left
GL11.glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right
GL11.glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right
GL11.glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Left
//RIGHT
GL11.glColor3f(1.0f, 1.0f, 0.0f);
GL11.glVertex3f(1.0f, 1.0f, 1.0f); // Top Left
GL11.glVertex3f(1.0f, 1.0f, -1.0f); // Top Right
GL11.glVertex3f(1.0f, -1.0f, -1.0f); // Bottom Right
GL11.glVertex3f(1.0f, -1.0f, 1.0f); // Bottom Left
//BACK
GL11.glColor3f(0.0f, 0.0f, 1.0f);
GL11.glVertex3f(1.0f, 1.0f, -1.0f); // Top Left
GL11.glVertex3f(-1.0f, 1.0f, -1.0f); // Top Right
GL11.glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Right
GL11.glVertex3f(1.0f, -1.0f, -1.0f); // Bottom Left
//BOTTOM
GL11.glColor3f(1.0f, 0.0f, 1.0f);
GL11.glVertex3f(-1.0f, -1.0f, -1.0f); // Top Left
GL11.glVertex3f(1.0f, -1.0f, -1.0f); // Top Right
GL11.glVertex3f(1.0f, -1.0f, 1.0f); // Bottom Right
GL11.glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left
GL11.glEnd(); // Done Drawing The Quad
rtri += 0.5f;
rquad += -0.5f;
}
/**
* Poll Input
*/
public void pollInput()
{
// scroll through key events
while (Keyboard.next())
{
if (Keyboard.getEventKeyState())
{
if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE)
closeRequested = true;
else if (Keyboard.getEventKey() == Keyboard.KEY_F1)
{
fullscreen = !fullscreen;
System.out.println(fullscreen);
setDisplayMode(width, height, fullscreen);
}
}
}
if (Display.isCloseRequested())
{
closeRequested = true;
}
}
private void createWindow(String title, int width, int height,
int colourDepth, boolean fullscreeen)
{
try
{
DisplayMode[] modes = Display.getAvailableDisplayModes();
for (int i = 0; i < modes.length; i++)
{
DisplayMode current = modes[i];
if (current.isFullscreenCapable())
{
Display.setDisplayMode(current);
}
else
Display.setDisplayMode(new DisplayMode(width, height));
}
Display.setFullscreen(fullscreeen);
Display.setTitle(title);
Display.setVSyncEnabled(true);
Display.create();
}
catch (LWJGLException e)
{
Sys.alert("Error", "Initialisation failed!\n\n" + e.getMessage());
}
}
private void cleanUp()
{
Display.destroy();
}
public void setDisplayMode(int width, int height, boolean fullscreen)
{
// return if requested DisplayMode is already set
if ((Display.getDisplayMode().getWidth() == width)
&& (Display.getDisplayMode().getHeight() == height)
&& (Display.isFullscreen() == fullscreen))
{
return;
}
try
{
DisplayMode targetDisplayMode = null;
if (fullscreen)
{
DisplayMode[] modes = Display.getAvailableDisplayModes();
int freq = 0;
for (int i = 0; i < modes.length; i++)
{
DisplayMode current = modes[i];
if ((current.getWidth() == width)
&& (current.getHeight() == height))
{
if ((targetDisplayMode == null)
|| (current.getFrequency() >= freq))
{
if ((targetDisplayMode == null)
|| (current.getBitsPerPixel() > targetDisplayMode
.getBitsPerPixel()))
{
targetDisplayMode = current;
freq = targetDisplayMode.getFrequency();
}
}
// if we've found a match for bpp and frequence against
// the
// original display mode then it's probably best to go
// for this one
// since it's most likely compatible with the monitor
if ((current.getBitsPerPixel() == Display
.getDesktopDisplayMode().getBitsPerPixel())
&& (current.getFrequency() == Display
.getDesktopDisplayMode().getFrequency()))
{
targetDisplayMode = current;
break;
}
}
}
}
else
{
targetDisplayMode = new DisplayMode(width, height);
}
if (targetDisplayMode == null)
{
System.out.println("Failed to find value mode: " + width + "x"
+ height + " fs=" + fullscreen);
return;
}
Display.setDisplayMode(targetDisplayMode);
Display.setFullscreen(fullscreen);
}
catch (LWJGLException e)
{
System.out.println("Unable to setup mode " + width + "x" + height
+ " fullscreen=" + fullscreen + e);
}
}
public static void main(String[] argv)
{
DisplayExample displayExample = new DisplayExample();
displayExample.start();
}
}