Skip to main content
gamedev.net
🔒 Locked

[java] JAWT Problem

Started by dega512 Apr 11, 2006 at 10:38 PM 1 replies 2.2k views
Original Post
dega512
dega512
I have been trying to use JAWT (AWT Native Interface) and I keep getting an error (even when I try the examples that are in the api). When I call the JAWT_DrawingSurface lock method it always returns with JAWT_LOCK_ERROR. Does anyone have an idea on how to fix this? (I have tried JDK 1.3, 1.4 and 1.5; none work :( ) code: ------------------------------ JAWT awt; JAWT_DrawingSurface* ds; JAWT_DrawingSurfaceInfo* dsi; JAWT_Win32DrawingSurfaceInfo* dsi_win; jint lock; ... lock = ds->Lock(ds); // lock always returns JAWT_LOCK_ERROR -----------------------------
It's easy as 01, 10, 11
strtok
strtok
Please post the rest of the code leading up to the error.
dega512
dega512
/******* GLCanvas.h ***********/
/* DO NOT EDIT THIS FILE - it is machine generated */
#include
/* Header for class GLCanvas */

#ifndef _Included_GLCanvas
#define _Included_GLCanvas
#ifdef __cplusplus
extern "C" {
#endif
#undef GLCanvas_FOCUS_TRAVERSABLE_UNKNOWN
#define GLCanvas_FOCUS_TRAVERSABLE_UNKNOWN 0L
#undef GLCanvas_FOCUS_TRAVERSABLE_DEFAULT
#define GLCanvas_FOCUS_TRAVERSABLE_DEFAULT 1L
#undef GLCanvas_FOCUS_TRAVERSABLE_SET
#define GLCanvas_FOCUS_TRAVERSABLE_SET 2L
#undef GLCanvas_TOP_ALIGNMENT
#define GLCanvas_TOP_ALIGNMENT 0.0f
#undef GLCanvas_CENTER_ALIGNMENT
#define GLCanvas_CENTER_ALIGNMENT 0.5f
#undef GLCanvas_BOTTOM_ALIGNMENT
#define GLCanvas_BOTTOM_ALIGNMENT 1.0f
#undef GLCanvas_LEFT_ALIGNMENT
#define GLCanvas_LEFT_ALIGNMENT 0.0f
#undef GLCanvas_RIGHT_ALIGNMENT
#define GLCanvas_RIGHT_ALIGNMENT 1.0f
#undef GLCanvas_serialVersionUID
#define GLCanvas_serialVersionUID -7644114512714619750i64
#undef GLCanvas_serialVersionUID
#define GLCanvas_serialVersionUID -2284879212465893870i64
/*
* Class: GLCanvas
* Method: InitGL
* Signature: (II)V
*/
JNIEXPORT void JNICALL Java_GLCanvas_InitGL
(JNIEnv *, jobject, jint, jint);

/*
* Class: GLCanvas
* Method: PaintGL
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_GLCanvas_PaintGL
(JNIEnv *, jobject);

/*
* Class: GLCanvas
* Method: DeInitGL
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_GLCanvas_DeInitGL
(JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

/******** end ****************/



/******** GLCanvas.cpp ********/
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "winmm.lib")

#pragma comment(lib, "jawt.lib")

#include
#include
#include
#include
#include
#include
#include "GLCanvas.h"

HGLRC hRC = NULL;
HDC hDC = NULL;
float rot = 0.0f;

JNIEXPORT void JNICALL Java_GLCanvas_InitGL(JNIEnv *env, jobject canvas, jint w, jint h)
{
JAWT awt;
JAWT_DrawingSurface* ds;
JAWT_DrawingSurfaceInfo* dsi;
JAWT_Win32DrawingSurfaceInfo* dsi_win;
jboolean result;
jint lock;

awt.version = JAWT_VERSION_1_3;
result = JAWT_GetAWT(env, &awt);
assert(result != JNI_FALSE);
ds = awt.GetDrawingSurface(env, canvas);
assert(ds != NULL);

lock = ds->Lock(ds);

//if (!((lock & JAWT_LOCK_ERROR) == 0))
if (lock == JAWT_LOCK_ERROR)
{
MessageBox(NULL, "Lock Error!!!!!!!", "Error", MB_OK | MB_ICONERROR);
return;
}

dsi = ds->GetDrawingSurfaceInfo(ds);
dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;

MessageBox(NULL, "Start", "Info", MB_OK | MB_ICONINFORMATION);

HWND hWnd = dsi_win->hwnd;

if (hWnd == NULL)
{
MessageBox(NULL, "Null window handle1...", "Error", MB_OK | MB_ICONERROR);
return;
}

PIXELFORMATDESCRIPTOR pfd;
int iFormat;

hDC = dsi_win->hdc;

// set the pixel format for the DC
ZeroMemory( &pfd, sizeof( pfd ) );
pfd.nSize = sizeof( pfd );
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
iFormat = ::ChoosePixelFormat( hDC, &pfd );
SetPixelFormat( hDC, iFormat, &pfd );

hRC = wglCreateContext( hDC );
wglMakeCurrent( hDC, hRC );

if (h == 0)
h = 1;

glViewport(0, 0, w, h);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluPerspective(45.0f, (float)w / (float)h, 1.0f, 100.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

ds->FreeDrawingSurfaceInfo(dsi);
ds->Unlock(ds);
awt.FreeDrawingSurface(ds);
}

JNIEXPORT void JNICALL Java_GLCanvas_PaintGL(JNIEnv *env, jobject canvas)
{
JAWT awt;
JAWT_DrawingSurface* ds;
JAWT_DrawingSurfaceInfo* dsi;
JAWT_Win32DrawingSurfaceInfo* dsi_win;
jboolean result;
jint lock;

awt.version = JAWT_VERSION_1_3;
result = JAWT_GetAWT(env, &awt);
assert(result != JNI_FALSE);
ds = awt.GetDrawingSurface(env, canvas);
assert(ds != NULL);

lock = ds->Lock(ds);

if (!((lock & JAWT_LOCK_ERROR) == 0))
{
MessageBox(NULL, "Lock Error!!!!!!!", "Error", MB_OK | MB_ICONERROR);
return;
}

dsi = ds->GetDrawingSurfaceInfo(ds);
dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;

HWND hWnd = dsi_win->hwnd;

if (hWnd == NULL)
{
MessageBox(NULL, "Null window handle2...", "Error", MB_OK | MB_ICONERROR);
return;
}

if (rot >= 6.28f)
rot = 0.0f;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

glTranslatef(0.0f, 0.0f, -5.0f);
glRotatef(rot, 0.0f, 1.0f, 0.0f);
glBegin(GL_TRIANGLES);

glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);

glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);

glColor3f(0.0f, 0.0f, 0.0f);
glVertex3f( 1.0f, -1.0f, 0.0f);

glEnd();

SwapBuffers( hDC );
rot += 0.1f;

ds->FreeDrawingSurfaceInfo(dsi);
ds->Unlock(ds);
awt.FreeDrawingSurface(ds);
}

JNIEXPORT void JNICALL Java_GLCanvas_DeInitGL(JNIEnv *env, jobject canvas)
{
JAWT awt;
JAWT_DrawingSurface* ds;
JAWT_DrawingSurfaceInfo* dsi;
JAWT_Win32DrawingSurfaceInfo* dsi_win;
jboolean result;
jint lock;

awt.version = JAWT_VERSION_1_3;
result = JAWT_GetAWT(env, &awt);
assert(result != JNI_FALSE);
ds = awt.GetDrawingSurface(env, canvas);
assert(ds != NULL);

lock = ds->Lock(ds);

if (!((lock & JAWT_LOCK_ERROR) == 0))
{
MessageBox(NULL, "Lock Error!!!!!!!", "Error", MB_OK | MB_ICONERROR);
return;
}

dsi = ds->GetDrawingSurfaceInfo(ds);
dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;

HWND hWnd = dsi_win->hwnd;

if (hWnd == NULL)
{
MessageBox(NULL, "Null window handle3...", "Error", MB_OK | MB_ICONERROR);
return;
}

wglMakeCurrent( NULL, NULL );
wglDeleteContext( hRC );

ds->FreeDrawingSurfaceInfo(dsi);
ds->Unlock(ds);
awt.FreeDrawingSurface(ds);
}
/******** end ****************/


/******** GLCanvas.java *************/
import java.awt.*;

public class GLCanvas extends Canvas
{
static
{
System.loadLibrary("GLCanvasTest1");
}

public GLCanvas(int w, int h)
{
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable()
{
public void run()
{
DeInitGL();
}
}));

setSize(new Dimension(w, h));
//setPreferredSize(new Dimension(w, h));
InitGL(w, h);
}

public native void InitGL(int width, int height);
public native void PaintGL();
public native void DeInitGL();
}
/******** end **********************/
It's easy as 01, 10, 11

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.