Learning bumps...
BlitzMax Forums/OpenGL Module/Learning bumps...
| ||
Hey, I'm trying to learn some raw openGL, unsurprisingly, using this is ungodly fast, I'm getting like 6000-8000+fps :O Anyways, i'm trying to keep this box's orientation for the Y axis straight up and down. Here's an example illistrating the problem... S/A for rotation increments, and UP/DOWN cursors for movement SuperStrict GLGraphics 800, 600 Global Vertices:Float[] = [-1.0, 1.0, -10.0, 1.0, 1.0, -10.0, 1.0, -1.0, -10.0, -1.0, -1.0, -10.0]' X Y X? Global Colors:Float[] = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0] ' R G B? 'initalize stuff glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45.0, 1.3333, 1, 1000) glMatrixMode(GL_MODELVIEW) glLoadIdentity() Local r:Float = 0 'Rotation Local _FPS:Int ' FPS Local _FPSTICK:Int ' FPS ticker Local _FPSTIME:Int = MilliSecs() ' FPS Timer While Not KeyDown(KEY_ESCAPE) glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) 'Cls 'Add/Subtract rotation value with S/A If KeyHit(KEY_S) r:+2 If KeyHit(KEY_A) r:-2 If r > 359 r = 0 If r < 0 r = 359 'TRY to move block up and down... Problems... trying to increment the Y value If KeyDown(KEY_UP) Vertices[1]:+.2 Vertices[4]:+.2 Vertices[7]:+.2 Vertices[10]:+.2 If KeyDown(KEY_DOWN) Vertices[1]:-.2 Vertices[4]:-.2 Vertices[7]:-.2 Vertices[10]:-.2 'Enable certain drawing states glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_COLOR_ARRAY) 'Draw box glRotated(r,0,0,-10.0) 'Setrotation() ? glColorPointer(3, GL_FLOAT, 0, Colors) glVertexPointer(3, GL_FLOAT, 0, Vertices) glDrawArrays(GL_QUADS, 0, 4) 'Disable the enabled drawing states glDisableClientState(GL_VERTEX_ARRAY) glDisableClientState(GL_COLOR_ARRAY) 'FPS updating GLDrawText _FPS,0,0 _FPSTICK:+1 If MilliSecs() > _FPSTIME+1000 _FPS = _FPSTICK _FPSTICK = 0 _FPSTIME = MilliSecs() End If Flip 1 Wend End Basicly, when the box is rotated, if you try to move it, it will move in the direction it's rotated in. NOT the direction up and down like I want it too. Anyone know what i'm doing wrong? Also any tutorials out there that can help me learn openGL would be appriciated! |
| ||
Usually something like that would be to do with the order in which you are doing your `translates` and `rotates`. If you rotate first and then translate, the object will move along its rotated axis. You need to translate first to move it up, then do rotation. Also in your example you are basically increasing the Y coordinates but within the `object's rotated coordinate space`, so you're moving up and down within the objects axis, not the screen axis. That's what happens when you add to the object's coordinates, trying to translate it manually. You have to move the entire object's coordinate system vertically, not just the vertexes within it. I think. |
| ||
I'm not sure I get what you mean exactly. I moved around the rotating routine, (notice the astriks) SuperStrict GLGraphics 800, 600 Global Vertices:Float[] = [-1.0, 1.0, -10.0, 1.0, 1.0, -10.0, 1.0, -1.0, -10.0, -1.0, -1.0, -10.0]' X Y X? Global Colors:Float[] = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0] ' R G B? 'initalize stuff glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45.0, 1.3333, 1, 1000) glMatrixMode(GL_MODELVIEW) glLoadIdentity() Local r:Float = 0 'Rotation Local _FPS:Int ' FPS Local _FPSTICK:Int ' FPS ticker Local _FPSTIME:Int = MilliSecs() ' FPS Timer While Not KeyDown(KEY_ESCAPE) glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) 'Cls 'Add/Subtract rotation value with S/A If KeyHit(KEY_S) r:+2 If KeyHit(KEY_A) r:-2 If r > 359 r = 0 If r < 0 r = 359 'TRY to move block up and down... Problems... trying to increment the Y value If KeyDown(KEY_UP) Vertices[1]:+.2 Vertices[4]:+.2 Vertices[7]:+.2 Vertices[10]:+.2 If KeyDown(KEY_DOWN) Vertices[1]:-.2 Vertices[4]:-.2 Vertices[7]:-.2 Vertices[10]:-.2 'Enable certain drawing states glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_COLOR_ARRAY) 'Draw box glColorPointer(3, GL_FLOAT, 0, Colors) glVertexPointer(3, GL_FLOAT, 0, Vertices) glDrawArrays(GL_QUADS, 0, 4) glRotated(r,0,0,-10.0) 'Setrotation() ? ************************************************* 'Disable the enabled drawing states glDisableClientState(GL_VERTEX_ARRAY) glDisableClientState(GL_COLOR_ARRAY) 'FPS updating GLDrawText _FPS,0,0 _FPSTICK:+1 If MilliSecs() > _FPSTIME+1000 _FPS = _FPSTICK _FPSTICK = 0 _FPSTIME = MilliSecs() End If Flip 1 Wend End Also, what's the difference between rotatef and rotated? Both produce the same error for me. |
| ||
I was trying to learn ogl a while back. so I downloaded a few tutorial examples to help me learn but I got impatioent and gave up. follow the link to my signature and download the textured cube. it moves it along the z axis I thik all you have to do change from z to y and it should do what you want. it uses the mouse to rotate. |
| ||
hmm, I tried gltranslatef() still no avail... SuperStrict GLGraphics 800, 600 Global Vertices:Float[] = [-1.0, 1.0, -10.0, 1.0, 1.0, -10.0, 1.0, -1.0, -10.0, -1.0, -1.0, -10.0]' X Y X? Global Colors:Float[] = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0] ' R G B? 'initalize stuff glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45.0, 1.3333, 1, 1000) glMatrixMode(GL_MODELVIEW) glLoadIdentity() Local r:Float = 0 'Rotation Local _FPS:Int ' FPS Local _FPSTICK:Int ' FPS ticker Local _FPSTIME:Int = MilliSecs() ' FPS Timer While Not KeyDown(KEY_ESCAPE) glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) 'Cls 'Add/Subtract rotation value with S/A If KeyHit(KEY_S) r:+2 If KeyHit(KEY_A) r:-2 If r > 359 r = 0 If r < 0 r = 359 glRotatef(r,0,0,-10.0) 'Setrotation() ? ************************************************* 'TRY to move block up and down... Problems... trying to increment the Y value If KeyDown(KEY_UP) glTranslatef(0,-.2,0) If KeyDown(KEY_DOWN) glTranslatef(0,.2,0) 'Enable certain drawing states glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_COLOR_ARRAY) 'Draw box glColorPointer(3, GL_FLOAT, 0, Colors) glVertexPointer(3, GL_FLOAT, 0, Vertices) glDrawArrays(GL_QUADS, 0, 4) 'Disable the enabled drawing states glDisableClientState(GL_VERTEX_ARRAY) glDisableClientState(GL_COLOR_ARRAY) 'FPS updating GLDrawText _FPS,0,0 _FPSTICK:+1 If MilliSecs() > _FPSTIME+1000 _FPS = _FPSTICK _FPSTICK = 0 _FPSTIME = MilliSecs() End If Flip 1 Wend End on the bright side that change did get rid of the 'off center' rotating... |
| ||
Hmm, could it be because OpenGL by default assumes that the coordinate 0,0 are in the bottom left corner of the screen, and therefore a larger Y coord is actually nearer the top of the screen, so you're looking at your game world upside down? |
| ||
|
| ||
Interesting, thanks jesse, i'll look it over... Edit, can you explain what a/t are ? |
| ||
Alright, I got that much, but now i'm trying to create a little mini engine to draw rects around... How do I... -Change prepective to 0,0 = top left cornor? -Draw dimensions in pixels? here's what I have so far, i'm stumped... SuperStrict Framework pub.OpenGL Import BRL.GLGraphics GLGraphics 800, 600 Type TGLPrimative Field X:Float,Y:Float Field Ox:Float,Oy:Float Field RotAngle:Int Field Width:Int,Height:Int End Type Type TGLQuad Extends TGLPrimative Field v1x:Float, v1y:Float Field v2x:Float, v2y:Float Field v3x:Float, v3y:Float Field v4x:Float, v4y:Float Method Init(_x:Float,_y:Float,w:Int,h:Int) X = _x/800 Y = _y/600 Width = w/800 Height = h/600 Ox = X Oy = Y 'top left v1x = X v1y = Y 'top right v2x = X+Width v2y = Y 'bottom right v3x = X+Width v3y = Y-Height 'bottom left v4x = X v4y = Y-Height End Method Method Render() glTranslatef(x-Ox, y-Oy,0) glRotatef(RotAngle,0,0,1.0) glBegin(GL_QUADS) glColor3f(.2,.6,.55) glVertex3f(v1x,v1y,-.0001) glColor3f(.22,.7,.9) glVertex3f(v2x,v2y,-.0001) glColor3f(.56,.2,.5) glVertex3f(v3x,v3y,-.0001) glColor3f(.33,.9,.2) glVertex3f(v4x,v4y,-.0001) glEnd() End Method End Type 'other initalizing stuff InitalizeGL() 'initalize opengl stuff (beyound my comprehension at the moment) Local _FPS:Int ' FPS Local _FPSTICK:Int ' FPS ticker Local _FPSTIME:Int = MilliSecs() ' FPS Timer Local MyBox:TGLQuad = New TGLQuad MyBox.Init(200,200,100,100) 'Main loop, quit on KEY_ESCAPE While Not KeyDown(KEY_ESCAPE) glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) 'Cls but opengl glLoadIdentity MyBox.Render() 'FPS updating GLDrawText _FPS,0,0 _FPSTICK:+1 If MilliSecs() > _FPSTIME+1000 _FPS = _FPSTICK _FPSTICK = 0 _FPSTIME = MilliSecs() End If Flip 1 Wend End Function InitalizeGL() glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45.0, 1.3333, 1, 1000) glMatrixMode(GL_MODELVIEW) glLoadIdentity() End Function Nothing is being drawn oddly enough... I thought that 1.0 ment the whole screen so I divided 1 by 800 for x, which should give me pixels? I did the same for Y. I also looked at the DrawRect function in GLGraphics.mod... What is BeginOrtho and EndOrtho? Does that have to do with changing prepective? Thanks in advance! |
| ||
Just to clarify(because my post above doesn't seem very clear): -How does max2D draw in pixel units vs. whatever OGL uses (what does OGL use exactly?) And how many OGL measurements = how many pixels? This probably depends on the depth. -How does Max2D draw from the top cornor of the screen? -How do you move images seperatly, because Transitionf() seems to move the camera as a whole and not individual images. PS. I'm not looking at 3d, simply 3d accelerated 2d like max2d (i'm trying to figure out how it works) Thanks! |
| ||
Have you tried the nehe tutorials? they might help you figure things out. |
| ||
Just read them, they don't really explain a whole lot, other than how to do 3d tricks... |
| ||
there is not much I can help you with either sence I am kind of where you are at right now. I have some more code that might help you. hopefully this will help you with objects creation: |
| ||
Interesting, i'm trying to add rotation to your code (turning) It seems to be rotating the geometry and not the camera. Oh well, I'll learn eventually, just got to keep at it :) |
| ||
there are some video tutorials here if you are interested: http://www.videotutorialsrock.com/ it is in c but most of it works in bmax and the concept should be the same. |
| ||
If you use gluPerspective and you give it a `field of view angle`, it's very difficult to correlate that to an exact number of pixels so that you have a 1:1 match between pixel coords and world coords. I recommend that instead you use glFrustum() to create your perspective projection. You can then specify that you want the edges of your `near edge` to be 0,0 to 800,600 or whatever, and it should then map directly to the pixels on the screen so long as you don't move in Z and your near plane is at, I think, -1.0 If you use gluPerspective it's going to give you whatever coordinate system it comes up with based on the field of view. |
| ||
What exactly IS max2d in it's open GL form? And how does it do everything in pixels? |
| ||
I believe this is similar on how bmax does 2d. but you can always look at the module source. STRIPPED DOWN nehe tutorial 21: it has a lot to do with the ortho settings. |
| ||
Interesting! From the Nehe tutorial: The first parameter (0.0f) is the value that we want for the far left side of the screen. You wanted to know how to use actual pixel values, so instead of using a negative number for far left, I've set the value to 0. The second parameter is the value for the far right side of the screen. If our window is 640x480, the value stored in width will be 640. So the far right side of the screen effectively becomes 640. Therefore our screen runs from 0 to 639 on the x-axis (640 pixels). The third parameter (height) would normally be our negative y-axis value (bottom of the screen). But because we want exact pixels, we wont have a negative value. Instead we will make the bottom of the screen equal the height of our window. If our window is 640x480, height will be equal to 480. So the bottom of our screen will be 479. The fourth parameter would normally be the positive value for the top of our screen. We want the top of the screen to be 0 (good old fashioned screen coordinates) so we just set the fourth parameter to 0. This gives us from 0 to 479 on the y-axis (480 pixels). The last two parameters are for the z-axis. We don't really care about the z-axis so we'll set the range from -1.0f to 1.0f. Just enough that we can see anything drawn at 0.0f on the z-axis. So thats how you do pixel positioning... That would explain why the max2dGL source has a 'beginortho()' and 'Endortho()' functions. You still get all the 3d rotation/blending and stuff right? |
| ||
Very cool: Now I need to figure out how to make that box an image :) |
| ||
How'd you do the rotation? This is producing some wierd results... |
| ||
Ok, I fixed the problem, You have to translate to the x/y and draw at 0,0 rather then draw at the x/y ? Anyways, this causes problems with multible objects: Any ideas? |
| ||
I looked at your code and couldn't find anything wrong. what exactly is it you want to do? and what is it not doing? extra: here at http://www.glprogramming.com/red/ is just about the whole OGL red book 1.1 if you go here: http://www.glprogramming.com/red/chapter01.html you can read the "OpenGL Command Syntax" section which you don't seem to understand.:) [edit] I couldn't remember this one so I had to google it: ogl blue book: http://www.talisman.org/opengl-1.1/Reference.html |
| ||
Thanks for the links I'll look at them... I found the fix to my code... If you draw multible things you have to glLoadIdentity() between drawing them. |
| ||
here's a little stress test: I got 80 FPS... seems kind of slow, I mean when in 3d, for example, the leadwerks engine (uses opengl if I recall right), renders hundreds of thousands if not millions of polys. This is only 6000... Why the difference between 2d and 3d? Also just to mess around what little 'tricks' could I use to speed it up? |
| ||
if you read the whole red book chapter 2 you'll get an idea on how it works. most of the speed is gained by using vector arrays fo the different type of objects drawn. There is not much you can improve on what you are doing because all you are doing is quads. But for terrain and shapes it would really help the speed If you send a single triangle array with hundreds of triangles to the graphics card instead of sending a bunch of triangle/quads objects separately. you get me? |
| ||
So is my code above 'single surface'? It would seem not because i'm rendering each box seperately |
| ||
correct. and sorry I can't help you beyound this point. This is up to where my skills reach(I know, not much :) ) and I don't want to confuse you. I think, eitherway it should be faster than the bmax version sence you are not initializing ortho everytime you draw a box(orthobegin/orthoend). |
| ||
Cool thanks for the help jesse, I'm doing to try and do a basic sprite system just for learning experience, after that i'll try my hand at creating a system for outputting basic 3d primatives (sphere, cube, polyhedron, prisms, ect.) Next step: Textures for images... fun :) |