Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (769)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (855)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  OpenGL with Frame acting weird. Can someone please look over code.  (Read 1432 times)
0 Members and 1 Guest are viewing this topic.
Offline Epo

Senior Newbie


Projects: 1


Green Tea and swords


« Posted 2006-02-12 00:43:50 »

Hello. I am practicing with openGL some more, before i even start a new project and I am having this slight problem with openGl drawing to a canvas with in a frame. It draws blue(since thats the color I picked) every where and even on the frame's border. And on my Command Prompt if I move it over it.

Maybe someone could look over my source code(Remember this is just practice code so ignore the uglyness) and see if I am doing something wrong.

I used these when I did it.
Java SDK/JDK = jdk1.5.0_06
Java Run Time= jre1.5.0_06
JOGL Version  =JSR-231 beta 02 - January 4

Thanks In advanced.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
import java.awt.*;
import javax.media.opengl.*;
import javax.swing.*;


public class test{

private int checkC = 0;

private AWTGraphicsDevice GLGD;
private AWTGraphicsConfiguration GLGC;
private GLDrawable GLDraw;
private GL mainGL;
private GLCapabilities GLCap;
private GLContext GLCon;
private Graphics2D g2d;
private GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
private Canvas mainC;

private Frame frmTest = new Frame("Test");


public void setup(){
GLCap = new GLCapabilities();
GLCap.setDoubleBuffered(false);
GLCap.setSampleBuffers(false);
GLCap.setHardwareAccelerated(false);
GLCap.setRedBits(8);
GLCap.setBlueBits(8);
GLCap.setGreenBits(8);
GLCap.setAlphaBits(8);
//GLGD = new AWTGraphicsDevice(env.getDefaultScreenDevice());
//GLGC=(AWTGraphicsConfiguration)GLDrawableFactory.getFactory().chooseGraphicsConfiguration(GLCap,null,GLGD);

mainC = new Canvas();

GLDraw =GLDrawableFactory.getFactory().getGLDrawable(mainC,GLCap,null);
GLDraw.setSize(640,480);

mainC.setIgnoreRepaint(true);

GLCon = GLDraw.createContext(null);
GLCon.setSynchronized(true);

if (GLContext.getCurrent()==null){
System.out.println("Nothing is Current");
}else{
GLContext.getCurrent().release();
System.out.println("Whatever was current is Released");
}//END IF/ELSE STATEMENT


frmTest.setVisible(true);
frmTest.setIgnoreRepaint(true);
frmTest.setSize(640,480);
mainC.setVisible(true);
frmTest.add(mainC);
frmTest.setResizable(false);


mainC.addNotify();

GLDraw.setRealized(true);

checkC=GLCon.makeCurrent();

if (checkC == GLContext.CONTEXT_NOT_CURRENT)
System.out.println("NOT CURRENT");
else if (checkC == GLContext.CONTEXT_CURRENT_NEW)
System.out.println("NEW CURRENT");
else if (checkC == GLContext.CONTEXT_CURRENT)
System.out.println("Context Current");


loopmain();
}//END METHOD




public void loopmain(){

mainGL = GLCon.getGL();


mainGL.glClearColor(0.0f,.05f,.75f,1.0f);

mainGL.glViewport(0,0,640,480);

mainGL.glMatrixMode(mainGL.GL_PROJECTION);
mainGL.glLoadIdentity();
mainGL.glOrtho((double)0,(double)640,(double)0,(double)480,(double)0,(double)1);

mainGL.glDisable(mainGL.GL_DEPTH_TEST);
mainGL.glColor3f(1.0f,0f,0f);


while(true){
mainGL = GLCon.getGL();

mainGL.glClear(mainGL.GL_COLOR_BUFFER_BIT);

mainGL.glBegin(mainGL.GL_POINTS);
for (int a=0;a<40;a++)
mainGL.glVertex2i(320,a+50);

mainGL.glEnd();

mainGL.glFlush();
}//end while

}//END METHOD




public static void main(String args[]){
new test().setup();

}//END METHOD




}//END CLASS
Offline dovkruger

Senior Newbie




Java games rock!


« Reply #1 - Posted 2006-02-12 04:19:52 »

This looks very odd. You are treating JOGL like it's C, but in Java you have a threaded implementation, with an animator to run through the frames. I'm not saying this won't work, maybe this is what all the gamers do, but if so it's new to me.
Offline Epo

Senior Newbie


Projects: 1


Green Tea and swords


« Reply #2 - Posted 2006-02-12 04:45:45 »

For Some reason it works with Double Buffer, but not Single Buffer. Weird. When I turn Double Buffer on and get rid of flush and switch  it with the  GLDrawable swapbufffer() method It seems to my eyes work fine( That is until I minimize it, but I fixed that for I can).  Also it goes real slow with lag when I move the window around if I dont use the java2d opengl pipeline. (-Dsun.java2d.opengl=true). mmmmmmmmmm
1  
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Ka-El

Senior Newbie





« Reply #3 - Posted 2006-02-12 07:27:19 »

weirdest piece of code i've seen. don't make sense to me. i think when u use gl with Canvas u need to override its paint method and make the context current from there and draw and swap buffer. that might explained why u may seen the result in double buffered mode. try looking into the demo package's source (DualContext). u are trying to draw onto the Canvas, right?
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (1573 views)
2018-06-10 19:43:48

EgonOlsen (1657 views)
2018-06-10 19:43:44

EgonOlsen (1145 views)
2018-06-10 19:43:20

DesertCoockie (1573 views)
2018-05-13 18:23:11

nelsongames (1174 views)
2018-04-24 18:15:36

nelsongames (1664 views)
2018-04-24 18:14:32

ivj94 (2421 views)
2018-03-24 14:47:39

ivj94 (1631 views)
2018-03-24 14:46:31

ivj94 (2719 views)
2018-03-24 14:43:53

Solater (884 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!