Could not find a valid pixel format ...

I’m working on a space shooter game.

It works fine on some computers and on some I get

org.lwlgl.LWLGLException: Could not find a valid pixel format
at org.lwgl.opengl.GL11.glGenTextures(GL11.java:1791)
ar raz.GameGraphics.Renderer.convertToGlTexture(Renderer.Java:485)
ar raz.GameGraphics.Renderer.LoadTexture(Renderer.Java:467)

I can’t figure out what to do… I’m using png with an alpha channel and use pixel format RGBA 16 or 32 bpp.

Any clu as what goes wrong would be appreceiated.

Should I try experimenting with pixel formats to display.create ? Is there a way to enumerate all pixel formats that are supported?

It’s odd that the error occur at glGenTextures I think… shouldn’t the error be on Display.setDisplayMode if it could not find a valid pixel format? Or does it only have to do with how the textures are stored?

Any help would be much appreceiated…

Here is an error log if that helps any…

An unexpected error has been detected by HotSpot Virtual Machine:

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d6c5c85, pid=468, tid=864

Java VM: Java HotSpot™ Client VM (1.5.0_02-b09 mixed mode, sharing)

Problematic frame:

V [jvm.dll+0x85c85]

--------------- T H R E A D ---------------

Current thread (0x003a3c20): JavaThread “main” [_thread_in_vm, id=864]

siginfo: ExceptionCode=0xc0000005, reading address 0x00000000

Registers:
EAX=0x0006f844, EBX=0x00000000, ECX=0x003a41b8, EDX=0x003a41f8
ESP=0x0006f834, EBP=0x0006f848, ESI=0x003a41f4, EDI=0x003a41f0
EIP=0x6d6c5c85, EFLAGS=0x00010206

Top of Stack: (sp=0x0006f834)
0x0006f834: 10035074 003a3c20 00000000 003a41f0
0x0006f844: 003a41f4 0006f874 6d6c5bf4 003a3cdc
0x0006f854: 00000000 1002a180 1002a178 00000000
0x0006f864: 003a3c20 10035074 003a3cdc 003a3c20
0x0006f874: 00000000 1000136a 003a3cdc 00000000
0x0006f884: 1002a180 1002a178 003a3cdc 00000027
0x0006f894: 00000008 00000010 10001582 003a3cdc
0x0006f8a4: 10035074 00000008 003a3cdc 00000000

Instructions: (pc=0x6d6c5c85)
0x6d6c5c75: 00 00 8b 7d f8 85 ff 0f 84 07 01 00 00 8b 5d 0c
0x6d6c5c85: ff 33 e8 88 c4 ff ff 85 c0 59 74 13 ff 75 10 ff

Stack: [0x00030000,0x00070000), sp=0x0006f834, free space=254k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V [jvm.dll+0x85c85]
V [jvm.dll+0x85bf4]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j org.lwjgl.opengl.Win32Display.createContext(Lorg/lwjgl/opengl/PixelFormat;)V+0
j org.lwjgl.opengl.Display.create(Lorg/lwjgl/opengl/PixelFormat;)V+32
j org.lwjgl.opengl.Display.create()V+7
j raz.GameGraphics.Renderer.()V+315
j raz.SpaceWarClient.Client.startScreen()V+8
j raz.SpaceWarClient.Client.connect()V+0
j raz.SpaceWarClient.Client.main([Ljava/lang/String;)V+183
v ~StubRoutines::call_stub

--------------- P R O C E S S ---------------

Java Threads: ( => current thread )
0x00a66530 JavaThread “Low Memory Detector” daemon [_thread_blocked, id=1020]
0x00a65108 JavaThread “CompilerThread0” daemon [_thread_blocked, id=988]
0x00a643a0 JavaThread “Signal Dispatcher” daemon [_thread_blocked, id=868]
0x00a61710 JavaThread “Finalizer” daemon [_thread_blocked, id=544]
0x00a60230 JavaThread “Reference Handler” daemon [_thread_blocked, id=1288]
=>0x003a3c20 JavaThread “main” [_thread_in_vm, id=864]

Other Threads:
0x00a5d990 VMThread [id=348]
0x00a80fd8 WatcherThread [id=1364]

VM state:not at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread: None

Heap
def new generation total 576K, used 167K [0x22ad0000, 0x22b70000, 0x22fb0000)
eden space 512K, 20% used [0x22ad0000, 0x22ae9f48, 0x22b50000)
from space 64K, 100% used [0x22b60000, 0x22b70000, 0x22b70000)
to space 64K, 0% used [0x22b50000, 0x22b50000, 0x22b60000)
tenured generation total 1408K, used 91K [0x22fb0000, 0x23110000, 0x26ad0000)
the space 1408K, 6% used [0x22fb0000, 0x22fc6c48, 0x22fc6e00, 0x23110000)
compacting perm gen total 8192K, used 171K [0x26ad0000, 0x272d0000, 0x2aad0000)
the space 8192K, 2% used [0x26ad0000, 0x26afaf58, 0x26afb000, 0x272d0000)
ro space 8192K, 62% used [0x2aad0000, 0x2afd8018, 0x2afd8200, 0x2b2d0000)
rw space 12288K, 46% used [0x2b2d0000, 0x2b85c620, 0x2b85c800, 0x2bed0000)

Dynamic libraries:
0x00400000 - 0x0040c000 C:\Program Files\Java\jre1.5.0_02\bin\javaw.exe
0x77f50000 - 0x77ff7000 C:\WINDOWS\System32\ntdll.dll
0x77e60000 - 0x77f46000 C:\WINDOWS\system32\kernel32.dll
0x77dd0000 - 0x77e5d000 C:\WINDOWS\system32\ADVAPI32.dll
0x78000000 - 0x78087000 C:\WINDOWS\system32\RPCRT4.dll
0x77d40000 - 0x77dcd000 C:\WINDOWS\system32\USER32.dll
0x7f000000 - 0x7f041000 C:\WINDOWS\system32\GDI32.dll
0x77c10000 - 0x77c63000 C:\WINDOWS\system32\MSVCRT.dll
0x6d640000 - 0x6d7c5000 C:\Program Files\Java\jre1.5.0_02\bin\client\jvm.dll
0x76b40000 - 0x76b6c000 C:\WINDOWS\System32\WINMM.dll
0x6d280000 - 0x6d288000 C:\Program Files\Java\jre1.5.0_02\bin\hpi.dll
0x76bf0000 - 0x76bfb000 C:\WINDOWS\System32\PSAPI.DLL
0x6d610000 - 0x6d61c000 C:\Program Files\Java\jre1.5.0_02\bin\verify.dll
0x6d300000 - 0x6d31d000 C:\Program Files\Java\jre1.5.0_02\bin\java.dll
0x6d630000 - 0x6d63f000 C:\Program Files\Java\jre1.5.0_02\bin\zip.dll
0x10000000 - 0x10055000 C:\Games\SpaceWar\lwjgl.dll
0x72280000 - 0x722a8000 C:\WINDOWS\System32\DINPUT.dll
0x5ed00000 - 0x5edc6000 C:\WINDOWS\System32\OPENGL32.dll
0x68b20000 - 0x68b3e000 C:\WINDOWS\System32\GLU32.dll
0x51000000 - 0x51049000 C:\WINDOWS\System32\DDRAW.dll
0x73bc0000 - 0x73bc6000 C:\WINDOWS\System32\DCIMAN32.dll
0x77c00000 - 0x77c07000 C:\WINDOWS\system32\VERSION.dll
0x5ad70000 - 0x5ada4000 C:\WINDOWS\System32\uxtheme.dll
0x74720000 - 0x74764000 C:\WINDOWS\System32\MSCTF.dll

VM Arguments:
java_command: C:\Games\SpaceWar\SpaceWar.jar

Environment Variables:
PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem
USERNAME=Daniel
OS=Windows_NT
PROCESSOR_IDENTIFIER=x86 Family 6 Model 7 Stepping 3, GenuineIntel

--------------- S Y S T E M ---------------

OS: Windows XP Build 2600 Service Pack 1

CPU:total 1 family 6, cmov, cx8, fxsr, mmx, sse

Memory: 4k page, physical 261672k(88652k free), swap 633880k(480764k free)

vm_info: Java HotSpot™ Client VM (1.5.0_02-b09) for windows-x86, built on Mar 4 2005 01:53:53 by “java_re” with MS VC++ 6.0

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  org.lwjgl.opengl.Win32Display.createContext(Lorg/lwjgl/opengl/PixelFormat;)V+0
j  org.lwjgl.opengl.Display.create(Lorg/lwjgl/opengl/PixelFormat;)V+32
j  org.lwjgl.opengl.Display.create()V+7

This basicly says that either your gfx-chip is unsupported or (and much more likely) the gfx-drivers need to be updated.

Well, I’m not sure… It’s failed to run on a couple of different computers, while it runs on my very old celeron 500 mhz with integrated graphics… and some other not to modern systems.

It failed on my brother’s Radeon 9700 (I think it was…), and he’s a very active gamer that always gets the latest drivers. It should work on a relatively modern card like that, otherwise it’s pretty useless.

Is there some test application I that can be run just to see if a card is compatible (and thus showing if the game should be able to run)?

states set in opengl:

        glEnable(GL_TEXTURE_2D);
        glEnable(GL_BLEND);
        glEnable(GL_LINE_SMOOTH);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

and it fails on the command:

    IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();

-> glGenTextures(buf); // Create Texture In OpenGL

fails here acording to error msg…

I get the same thing using Win32 w/ S3 ProSavage Twister with the latest drivers. I’m pretty sure its cause the ProSavage drivers don’t expose any WGL extensions, specifically WGL_EXT_extensions_string or WGL_ARB_extensions_string which appears to be required by LWJGL making it OpenGL version 1.2 and higher only… of course I would love to be wrong so I can use my laptop for development. :-\

That could be the problem…

I only use OpenGl 1.1 function calls… windows by default comes only with the GL 1.1 standard (or so I read while skimming around the net)…

So maybe lwjgl internally does stuff that needs GL 1.2… maybe it would work on more systems if you could restrict lwjgl to only use 1.1 stuff…

Is there another option to do fast 2d rendering (the game only uses 2d graphics) in java? I’m doing a lot of rotations (and I read that rotations are not hardeware accelerated in java 1.5…), that’s why I’m not using the native java graphics…

also there is of course a lot of nice keyboard and sound stuff in lwjgl that makes life easier.

I want as many people as possible to be able to play the game without any hassle… as of now only 3 of 6 of my friends who have tested it have been able to run it… the other ones have all got the same - “Could not find valid pixel format” error.

I think alot of people will not bother if they have to go through all the hassle of going out and finding openGl drivers for their graphics card… it’s asking alot just to ask them to download 1.5 runtime… Maybe java isn’t such a great choice for making games after all? But I love to program in it… is there anyway to use DirectX with java? At least Microsoft is anxious to see it running on all systems…

DirectX…Java… Easy tiger. There is nothing wrong with using Java as a game programming language and it’s not really OpenGL that is at fault either. I presume that the assumption is made with LWJGL that unlike us ‘weird folk’ with our antique graphics cards, most people have at least a reasonably funky nVidia or ATI card installed. And it’s not that odd an assumption, considering we are now at a stage where most drivers provide at least some form of subset of support for OpenGL 2.0.

However, to maximise support, there should be a very good reason why LWJGL requires 1.2 and above, although if there is, it may have nothing to do with the problem we are having here.

first of all, what version of LWJGL ?, coz I cant locate a createContext in Win32Display… (but yeah, lwjgl still shouldn’t crash - but it might be a fixed bug).
as for the extension stuff, I am not sure - but I’ll look into it. There is no reason for LWJGL to require 1.2 at all.

I’m using Lwjgl 0.97 (lwjgl-win32-0.97.1.zip)…

As I said… Java is probably my favourite language at the moment… and programming this game and using Lwjgl has been a thoroughly enjoyable experience… until it came to testing it on my friends computers…

It’s important that it’s easy to get it to run, some of their systems are not so ancient… some are. I’ll try to get together a list of the graphics cards that don’t work… my brother who has an ati card (forget which one) that was modern a year or two ago can’t get it to run, and that’s bad… but maybe he can get some updated drivers, I haven’t asked him yet.

Two cards that can’t run it are (maybe because of bad driver?):

ATI Rage Mobility (laptop - googling reveals that a lot of older laptops have problems when it comes to OpenGL)
3 Savage4 (incomplete information?.. that’s what he told me…)

It works perfectly on my TI 4200… and on an ancient compaq presario w/ celeron 500 mhz and integrated graphics… and also on some other not so hot systems.

Hi Matzon,

Me too - LWJGL 0.97. Did used to work fine back in the 0.6 / 0.7 days. Looks like Aramaz is having probs with the S3 Savage chipset too.

It would be great if we could use DirectX with Java. More poeple got some version of DirectX installed, and it’s got better drivers than OpenGL. Must be a reason why most PC games use DirectX? But Java and MS don’t mix, it will never happen :frowning:

As for the pixel format problem, try different bit depths. Have seen problems with switching to a different bit depth than what is currently used by the desktop. It would help if you could post the code used to create the display, in case you’re doing something obviously wrong.

As Matzon said, LWJGL don’t require OpenGL 1.2. I’ve run my game on a TNT2 and I doubt it is 1.2 compatible. But it do require OpenGL drivers. It will not fall back on MS software renderer unless you set a system property.

A fairly high percentage of Macs only have OpenGL 1.1 and everything I’ve written runs fine on them.
Trouble getting things to work is almost entirely down to buggy drivers for older cards that manufacturers simply don’t care about any more (the age and speed of the CPU have almost no relevance here). Before you go running to DirectX for help you ought to be aware that it’s just as fraught with problems, and it doesn’t work on the Mac or Linux which is half of the point of using Java.

Cas :slight_smile:

More likely its because they’re either doing a simultaneous version on the Xbox, or the rapidly expanding D3DX library which provides all sorts of fancyness out of the box.

Probably not, but I bet it supports a whole range of 1.2, 1.3 and possibly 1.4 extensions, just as my useless Savage driver does. Just not the whole lot to get the official compatibility stamp. The question is, does LWJGL crash if the driver does not expose any WGL extensions at all?
If it does require the WGL_xxx_extensions_string, then to guarentee compatibility, all cards must be OpenGL 1.2 certified even if the library uses nothing else.

[quote]As for the pixel format problem, try different bit depths. Have seen problems with switching to a different bit depth than what is currently used by the desktop. It would help if you could post the code used to create the display, in case you’re doing something obviously wrong.
[/quote]
I figured that something could go wrong if I switched bit depth, so for now I use the same bit depth and resolution that is used on the system… but things still crash…

anyway, here is the code:


            Display.setFullscreen(true);
            Display.create();
            screenWidth = Display.getDisplayMode().getWidth();
            screenHeight = Display.getDisplayMode().getHeight();

            glEnable(GL_TEXTURE_2D);
            glEnable(GL_BLEND);
            glEnable(GL_LINE_SMOOTH);

            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            glOrtho(0d, orthoX, 0d, orthoY, 0d, 100d);
            
            glMatrixMode(GL_MODELVIEW);
            glClearColor(0, 0, 0, 1);
            glClear(GL11.GL_COLOR_BUFFER_BIT);

            Keyboard.create();

That’s all there is in the method that sets up rendering… so it’s very simple…

And here is the code that converts a ng file to an openGL texture:
(this is where it actually crashes according to the stack trace… on the glGenTextures(buf))

   
private int convertToGlTexture(BufferedImage tex) {
        // Put Image In Memory
        ByteBuffer scratch = ByteBuffer.allocateDirect(4 * tex.getWidth() * tex.getHeight());

        byte data[] = (byte[]) tex.getRaster().getDataElements(0, 0, tex.getWidth(), tex.getHeight(), null);
        scratch.clear();
        scratch.put(data);
        scratch.rewind();

        // Create A IntBuffer For Image Address In Memory
        IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
        glGenTextures(buf); // Create Texture In OpenGL

        // Typical Texture Generation Using Data From The Image

        // Create Linear Filtered Texture
        glBindTexture(GL_TEXTURE_2D, buf.get(0));
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.getWidth(), tex.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, scratch);

        return buf.get(0);
}

thanx all who are taking interest in this thread! There is still hope left in the world! :slight_smile:

My brother’s card that it also doesn’t work is by the way:

Connect 3D Ati Radeon 9600XT

ATI Technologies, Inc. 3d rage pro agp 2x

Did not work with this card either… and he downloaded the latest drivers…

edit… found out that his card only has 4 mb video memory… that’s not very hot…

Rage Pro = teh sux.

Does Ultratron work?

Cas :slight_smile:

The 9600XT definitely does work with LWJGL, because there’s one in this PC. I suggest enumerating all the valid display formats and printing them out :slight_smile:

/Edit try compling and running this


import org.lwjgl.opengl.*;
/**
 *
 * @author Alan Waddington
 */
public class Main {
    
    /** Creates a new instance of Main */
    public Main() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
        DisplayMode[] modes = Display.getAvailableDisplayModes();
        for (int i=0; i<modes.length; i++)
            System.out.println(modes[i].toString());
        } catch (Exception e) {e.printStackTrace(); }
    }
    
}

On the 9600XT I get:


1280 x 768 x 32 @85Hz
512 x 384 x 16 @60Hz
320 x 240 x 16 @75Hz
1024 x 768 x 16 @72Hz
848 x 480 x 32 @60Hz
640 x 400 x 32 @75Hz
640 x 480 x 16 @75Hz
1280 x 960 x 16 @72Hz
1024 x 768 x 32 @85Hz
800 x 600 x 32 @70Hz
1280 x 768 x 16 @75Hz
1280 x 960 x 16 @60Hz
800 x 600 x 16 @85Hz
1024 x 768 x 16 @75Hz
400 x 300 x 32 @60Hz
800 x 600 x 32 @100Hz
800 x 600 x 16 @72Hz
848 x 480 x 16 @75Hz
1280 x 960 x 16 @70Hz
800 x 600 x 32 @56Hz
720 x 480 x 16 @60Hz
640 x 400 x 16 @60Hz
800 x 600 x 32 @90Hz
720 x 576 x 16 @75Hz
720 x 480 x 32 @75Hz
1024 x 768 x 32 @60Hz
720 x 576 x 32 @60Hz
720 x 576 x 32 @100Hz
800 x 600 x 32 @60Hz
848 x 480 x 16 @85Hz
1280 x 768 x 32 @60Hz
320 x 240 x 32 @60Hz
1280 x 1024 x 32 @60Hz
720 x 480 x 16 @85Hz
640 x 480 x 32 @100Hz
800 x 600 x 16 @75Hz
640 x 480 x 16 @72Hz
1024 x 768 x 16 @70Hz
1280 x 720 x 16 @85Hz
512 x 384 x 32 @75Hz
720 x 480 x 16 @75Hz
1280 x 720 x 32 @60Hz
1152 x 864 x 16 @60Hz
640 x 480 x 32 @90Hz
1152 x 864 x 16 @70Hz
320 x 200 x 16 @60Hz
800 x 600 x 16 @70Hz
848 x 480 x 32 @85Hz
800 x 600 x 32 @72Hz
640 x 480 x 16 @60Hz
800 x 600 x 16 @56Hz
720 x 480 x 32 @60Hz
1280 x 768 x 32 @75Hz
1152 x 864 x 32 @70Hz
640 x 400 x 32 @60Hz
720 x 576 x 32 @75Hz
1024 x 768 x 32 @70Hz
720 x 576 x 16 @59Hz
400 x 300 x 16 @60Hz
640 x 400 x 16 @75Hz
1280 x 720 x 32 @75Hz
1152 x 864 x 16 @75Hz
640 x 480 x 32 @75Hz
720 x 576 x 16 @60Hz
1024 x 768 x 16 @60Hz
1280 x 768 x 16 @60Hz
640 x 480 x 16 @90Hz
512 x 384 x 32 @60Hz
320 x 240 x 32 @75Hz
1024 x 768 x 32 @75Hz
512 x 384 x 16 @75Hz
800 x 600 x 16 @100Hz
1280 x 1024 x 16 @60Hz
848 x 480 x 32 @75Hz
400 x 300 x 16 @75Hz
1280 x 720 x 16 @60Hz
1152 x 864 x 32 @60Hz
640 x 480 x 32 @72Hz
848 x 480 x 16 @60Hz
320 x 240 x 16 @60Hz
640 x 480 x 16 @85Hz
1280 x 960 x 32 @72Hz
720 x 576 x 16 @100Hz
800 x 600 x 16 @60Hz
800 x 600 x 32 @85Hz
400 x 300 x 32 @75Hz
1024 x 768 x 16 @85Hz
1280 x 960 x 32 @70Hz
1280 x 768 x 16 @85Hz
320 x 200 x 32 @75Hz
320 x 200 x 16 @75Hz
800 x 600 x 32 @75Hz
640 x 480 x 16 @100Hz
1280 x 720 x 16 @75Hz
1152 x 864 x 32 @75Hz
1280 x 720 x 32 @85Hz
720 x 576 x 32 @59Hz
800 x 600 x 16 @90Hz
720 x 480 x 32 @85Hz
1024 x 768 x 32 @72Hz
640 x 480 x 32 @85Hz
320 x 200 x 32 @60Hz
1280 x 960 x 32 @60Hz
640 x 480 x 32 @60Hz

This will vary depending on your monitor of course

I also see that you are using Display.create() to create a default display. It is possible that some of the computers are set to 256 palettised colour mode as a default, which won’t really work with texturing. Try inserting this code before Display.create() & report back :wink:


            org.lwjgl.util.Display.setDisplayMode(
                   org.lwjgl.util.Display.getAvailableDisplayModes(
                   640, 480, -1, -1, 16, 32, 60, 85),
                   new String[] {"width=800", "height=600", "bpp="+
                   Display.getDisplayMode().getBitsPerPixel(), "freq=60"});

I find it really odd that the exception is occuring in GL11.glGenTextures, where it simply cannot happen. You’re not using some strange thread’y setup, are you (for example calling gl commands from a different thread than the one creating the Display)?

  • elias