|
Post by wallypog on Apr 26, 2015 14:11:11 GMT -5
Hi all: how do I translate this: for (int k = 0; k <= 1; k++) {
|
|
|
Post by wallypog on Apr 26, 2015 18:31:19 GMT -5
Sorry for my bad manners but I got disconnected before i said thanks in advance. Here is the rest of the code: Regards, John F for i = 0 to rSeg '{ glBegin(GL_QUAD_STRIP) for j = 0 to cSeg '{ for (int k = 0; k <= 1; k++) { double s# = (i + k) % rSeg + 0.5; double t# = j % (cSeg + 1);
x# = (c + r * cos(s# * TAU# / rSeg)) * cos(t# * TAU# / cSeg) y# = (c + r * cos(s# * TAU# / rSeg)) * sin(t# * TAU# / cSeg) z# = r * sin(s# * TAU# / rSeg)
u# = (i + k) / rSeg v# = t# / cSeg
glTexCoord2d(u, v); glNormal3f(2 * x#, 2 * y#, 2 * z#) glVertex3d(2 * x#, 2 * y#, 2 * z#) next '} next '} glEnd() next '} glFrontFace(GL_CCW)
|
|
|
Post by crazynate on Apr 26, 2015 19:17:12 GMT -5
All you really need to do is remove the semicolons and braces, initialize your variables, and change the formatting of the for loop to get it to compile:
dim i , j, k 'used in for-loops dim u, v dim s#, t#, u#, v#, x#, y#, z# dim r, c dim rSeg, cSeg dim TAU#
'TODO: Initialize variables
for i = 0 to rSeg glBegin(GL_QUAD_STRIP) for j = 0 to cSeg for k = 0 to 1 s# = (i + k) % rSeg + 0.5 t# = j % (cSeg + 1)
x# = (c + r * cos(s# * TAU# / rSeg)) * cos(t# * TAU# / cSeg) y# = (c + r * cos(s# * TAU# / rSeg)) * sin(t# * TAU# / cSeg) z# = r * sin(s# * TAU# / rSeg)
u# = (i + k) / rSeg v# = t# / cSeg
glTexCoord2d(u, v) glNormal3f(2 * x#, 2 * y#, 2 * z#) glVertex3d(2 * x#, 2 * y#, 2 * z#) next next glEnd() next glFrontFace(GL_CCW) swapbuffers()
I added the swapbuffers() to the end just because my computer doesn't like displaying the output otherwise.
Mind if I ask what the expected input and output is?
Nate
|
|
|
Post by wallypog on Apr 26, 2015 22:07:23 GMT -5
Thanks for the swift reply Nate. I got the code from 2 different sites and the code was identical except for i line for (int k = 0; k <= 1; k++) { for (int k = 1; k <= 0; k--) { So I got confused...... The code is supposed to draw a torus to which I'll add a checkerboard texture which is animated by sliding it around the ring. Thanks for your help. John
|
|
|
Post by crazynate on Apr 26, 2015 22:29:55 GMT -5
There didn't appear to be any difference when I ran it with the decrementing loop, though if you decide to use it the syntax would be:
for k = 1 to 0 step -1
|
|
|
Post by wallypog on Apr 27, 2015 0:21:07 GMT -5
hi Nate Me again. I'm like a clingon. So how do I get anything to display? Do I have to draw a wire frame torus? I usually code in BB4W where we use drawing commands but I have used freeBasic where drawing is done from memory. I've let Basic4gl slide in the last year or so but I want to get back into it. thanks again, John
|
|
|
Post by wallypog on Apr 27, 2015 21:35:05 GMT -5
Hello Nate: Please disregard my last post as I got the torus to display. Now for the texture. Thanks again, John
|
|
|
Post by wallypog on May 2, 2015 14:41:50 GMT -5
Hi everyone: I have a function that that creates an image, and I would like to save it as a texture and display it. Does it have to be converted to a bit map or can we skip that stage? Thanks, John
dim chessboard(63)(63)(2) function createChessbrd() 'Create 64 x 64 RGB image of a chessboardfunction createChessboard() dim i, j 'as int for i = 0 to 63 for j = 0 to 63 if ( ( ((i/8)%2) and ((j/8)%2) ) or ( not((i/8)%2) and not((j/8)%2) ) ) then chessboard(i)(j)(0) = 0x00 chessboard(i)(j)(1) = 0x00 chessboard(i)(j)(2) = 0x00 else endif chessboard(i)(j)(0) = 0xFF chessboard(i)(j)(1) = 0x00 chessboard(i)(j)(2) = 0x00 next next end function
|
|
|
Post by matthew on May 3, 2015 13:24:42 GMT -5
Hi, if you want to save the image as a texture, you could use the OpenGLPlugin. It's able to save image buffers as textures.
|
|